I have a ListView
and cannot display the sub items on the list… It only displays one or the other but not both. If I remove the number from below it will display the string (titles):
I want to display both Items and sub items.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.loadData();
String []titles_str = titles.toArray(new String[titles.toArray().length]);
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_2, android.R.id.text1, titles_str));
Number []subtitles_str = lengths.toArray(new Number[lengths.toArray().length]);
this.setListAdapter(new ArrayAdapter<Number>(this,
android.R.layout.simple_list_item_2, android.R.id.text2, subtitles_str));
}
Best Answer
you are using "this.setListAdapter" two times, only Second "this.setListAdapter" will reflect.
For your requirement, Please use
1) Using custom arrayadapter, Please check http://devtut.wordpress.com/2011/06/09/custom-arrayadapter-for-a-listview-android/
2) Using SimpleAdapter: