Android: TextView showing the package name instead of the actual text
source link: https://www.codesd.com/item/android-textview-showing-the-package-name-instead-of-the-actual-text.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Android: TextView showing the package name instead of the actual text
Text View in my fragment_main should be showing the String but instead it is showing the package name.
In my Main Activity Class,
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
ListView main_list;
ArrayAdapter<Cinema> adapter;
ArrayList<Cinema> ItemList = new ArrayList<Cinema>();
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.v("Check", "1");
final View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ItemList.addAll(initialization());
ListView main_list = (ListView) rootView.findViewById(R.id.mainlist);
adapter = new ListAdapater(rootView.getContext(), ItemList);
main_list.setAdapter(adapter);
main_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// TODO Auto-generated method stub
Intent i = new Intent(rootView.getContext(), CinemaDetails.class);
Bundle b = new Bundle();
b.putParcelable("Cinema", ItemList.get(position));
i.putExtra("Bundle", b);
startActivity(i);
}
});
return rootView;
}
public ArrayList<Cinema> initialization () {
ArrayList<Cinema> tempItemList = new ArrayList<Cinema>();
ArrayList<Movie> movielistone = new ArrayList<Movie>();
Movie movieone = new Movie(101, "MovieOne", "null", 5, "nULL");
Movie movietwo = new Movie(102, "Movietwo", "null", 3, "nuLL");
movielistone.add(movieone);
movielistone.add(movietwo);
Cinema cinemaone = new Cinema(01, "test", "ygn", 55555, movielistone, 3);
Cinema cinematwo = new Cinema(02, "test2", "ygn", 554555, movielistone, 3);
tempItemList.add(cinemaone);
tempItemList.add(cinematwo);
return tempItemList;
}
}
I use Array Adapter and the code for it is
public class ListAdapater extends ArrayAdapter<Cinema> {
private LayoutInflater inflater;
public ListAdapater(Context context, List<Cinema> itemList) {
super(context, R.layout.row, R.id.txt_cinemaname, itemList );
inflater = LayoutInflater.from(context) ;
// TODO Auto-generated constructor stub
}
@Override
public Cinema getItem(int position) {
// TODO Auto-generated method stub
return super.getItem(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Cinema cinema = this.getItem(position);
TextView txt_name;
TextView txt_movie;
if (convertView == null) {
convertView = inflater.inflate(R.layout.row, null);
txt_name = (TextView) convertView.findViewById(R.id.txt_cinemaname);
txt_movie = (TextView) convertView.findViewById(R.id.txt_moviesonshow);
convertView.setTag(new ItemViewHolder(txt_name, txt_movie));
} else {
ItemViewHolder viewHolder = (ItemViewHolder) convertView.getTag();
txt_name = viewHolder.getName();
txt_movie = viewHolder.getMoviename();
}
txt_name.setText("test");
Log.v("name", txt_name.getText().toString());
txt_movie.setText("");
for (Movie movie : cinema.getMovieonshow()) {
String temp = txt_movie.getText().toString();
txt_movie.setText(temp + movie.getName() + "\n");
}
return super.getView(position, convertView, parent);
}
public static class ItemViewHolder {
private TextView name;
private TextView moviename;
public ItemViewHolder() {}
public ItemViewHolder(TextView name, TextView moviename) {
super();
this.name = name;
this.moviename = moviename;
}
public TextView getName() {
return name;
}
public void setName(TextView name) {
this.name = name;
}
public TextView getMoviename() {
return moviename;
}
public void setMoviename(TextView moviename) {
this.moviename = moviename;
}
}}
I have never had this problem before. I tied to log the Text from the TextView and it shows "test" just like I put it there. Any suggestion? Thanks for reading.
I can't quite figure out exactly, but why are you passing in R.id.txt_cinemaname
in your ListAdapter constructor? The problem looks like you are passing in an Object (that string "com.example... is a pointer to an object, I'm guessing a TextView) rather than a string.
Also, shouldn't you be returning convertView
rather than super.getView(position, convertView, parent);
in your getView()
method?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK