问题
I have a Listview with a custom adapter. I am getting the standard
Your content must have a ListView whose id attribute is 'android.R.id.list'
error, however, My ListView has an android:id="@android:id/list"
value set. It's really doing my head in. Any suggestions?
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/Layout">
<ListView android:id="@android:id/list" style="@stlye/ListMenuView"></ListView>
</LinearLayout>
styles.xml
<resources>
<style name="Layout" parent="@android:Theme">
<item name="android:background">@drawable/background</item>
<item name="android:scaleType">fitXY</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:orientation">vertical</item>
</style>
<style name="ListMenuView">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:cacheColorHint">#00000000</item>
</style>
</resources>
My onCreate method:
/** Called when the activity is first created. */
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.main );
m_menu = new ArrayList<ListItemData>();
populateMenu();
this.m_adapter = new ListMenuAdapter( this, R.layout.list_item, m_menu );
setListAdapter(this.m_adapter);
}
Any Ideas?
回答1:
android:id="@android:id/list"
works perfectly, My issue was I had a Splash screen that inherited a base class which was inheriting ListActivity and had no ListView defined for the splash screen activity. I have altered the SplashScreen to just inherit Activity. All works as expected.
回答2:
I was facing the same issue. I extende Activity instead of ListActivity class and this resolved my problem.
回答3:
You are saying that you use custom adapter, but from code i can't see such adapter. Here you can download whole android project,http://blog.sptechnolab.com/wp-content/uploads/2011/02/listBlog.zip.
来源:https://stackoverflow.com/questions/5495603/listview-whose-id-attribute-is-android-r-id-list-error-when-i-have-the-listvie