Your Content Must Have a Listview Whose Id Attribute Is 'Android.R.Id.List'

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

Rename the id of your ListView like this,

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

Since you are using ListActivity your xml file must specify the keyword android while mentioning to a ID.

If you need a custom ListView then instead of Extending a ListActivity, you have to simply extend an Activity and should have the same id without the keyword android.

java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

The problem is here :

android:id="@+id/list"

you are adding a new id for your ListView but ListFragment needs a default Android ListView Id

change your ListView Id to :

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

your content must have a listview whose id attribute is ' android.r.id.list ' .

compare your code nothing difference....

Sample Image

mainActivity

package com.example.testdemo;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Dialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ListActivity {

private TextView text;
private static final String[] items = { "test", "test1", "test2", "test3",
"test4", "test5", "test6" };

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_);



setListAdapter(new ArrayAdapter<String>(this, R.layout.lable,
R.id.label, items));
text = (TextView) findViewById(R.id.selection);

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
text.setText("" + items[position]);
super.onListItemClick(l, v, position, id);
}


}
}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

<ListView

android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false" />

</LinearLayout>

row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dip"
android:src="@drawable/ic_launcher" />

<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

</LinearLayout>

your content must have a listview whose id attribute is 'android.r.id.list'

Your listView with id = "@android:id/list" must be part of activity, not a fragment. But in your code your list view is part of fragment. You can use common activity instead of listActivity and ListFragment (as parent of your PlaceholderFragment class). Or you can move your list from your fragment to your activity.

Android listview error: Your content must have a ListView whose id attribute is 'android.R.id.list' but i have two listviews

Problem with your Activity. May be you extend ListActivity.

You have to extend an Activity will resolve your issue

Second solutions is
define id as below format

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


Related Topics



Leave a reply



Submit