Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>

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?

like image 278
thepearson Avatar asked Mar 31 '11 05:03

thepearson


3 Answers

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.

like image 165
thepearson Avatar answered Nov 17 '22 13:11

thepearson


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

like image 37
Chetan Avatar answered Nov 17 '22 15:11

Chetan


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.

like image 1
user609239 Avatar answered Nov 17 '22 13:11

user609239