Android: Your content must have a ListView whose id attribute is android.R.id.list

后端 未结 3 1285
难免孤独
难免孤独 2020-12-08 14:46

I\'m getting this run-time error and I\'m really struggling to get to the bottom of it: \"Your content must have a ListView whose id attribute is android.R.id.list\".

<
3条回答
  •  悲哀的现实
    2020-12-08 15:13

    If you have more than one ListView in your layout you should not extend ListActivity but rather extend Activity and handle the ListViews yourself like;

    ListView list1 = (ListView) findViewById(R.id.myList1);
    list1.setAdapter(...);
    
    ListView list2 = (ListView) findViewById(R.id.myList2);
    list2.setAdapter(...);
    

    ListActivity is a shorthand helper class that makes life easier when you are working with only one ListView in your layout.

提交回复
热议问题