I’m trying to add a textview dynamically to a listview as follows. I see items appearing in the listview but they show up like this
android.widget.TextView@44f076d0
android.widget.TextView@44f07b58
android.widget.TextView@44f07f50
etc...
ArrayList<TextView> tv = new ArrayList<TextView>();
for(int i=0; i < 10; i++){
TextView t = new TextView(this);
t.setText("hi there");
tv.add(t);
}
ArrayAdapter<TextView> wordAdapter = new ArrayAdapter<TextView>(this,
android.R.layout.simple_list_item_1, android.R.id.text1,
tv);
this.articleListView.setAdapter(wordAdapter);
That’s because you are passing off the ArrayList of TextView Objects in the parameter for what the Adapter should display. Therefore, your
tvlist Objects are having theirtoString()method called.toString()for TextViews will give youTextView@numberso this is expected. Change yourtvArrayList to an ArrayList ofString, don’t make any new TextViews and just pass off that new String ArrayList instead oftv. Your text will display fine then.