Your content MUST have a ListView whose id attribute is 'android.R.id.list'

Asked 2 years ago, Updated 2 years ago, 94 views

First of all, the contents of the XML file are as follows.

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/list" >
</ListView>

This is the content of the activity.

public class ExampleActivity extends ListActivity {
    /** /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainlist);
    }
}

I didn't do anything else. However, the following error occurs.

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

I even wrote android:id="@+id/list" in xml. What's the problem?

android android-listview

2022-09-22 21:28

1 Answers

Please modify the ID of ListView as below.

<ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>

If you use ListActivity, you must have the list view ID android:id="@android:id/list" in xml.

If you want to create a custom list view, don't inherit ListActivity, just inherit Activity and give me the same ID except for the android keyword.


2022-09-22 21:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.