开发者

ListView whose id attribute is 'android.R.id.list' Error when I have the ListView id set correctly

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>

st开发者_运维问答yles.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?


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.


I was facing the same issue. I extende Activity instead of ListActivity class and this resolved my problem.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜