您的内容必须有一个 id 属性为“android.R.id.list"的 ListView [英] Your content must have a ListView whose id attribute is 'android.R.id.list'
问题描述
我创建了一个像这样的 xml 文件:
I have created an xml file like this:
<?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>
和一个活动:
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);
}
}
如你所见,我没有做任何其他事情.但我收到错误:
As you see, I have not done anything else. But I'am getting the error:
您的内容必须有一个 id 属性为 'android.R.id.list' 的 ListView
Your content must have a ListView whose id attribute is 'android.R.id.list'
即使我的 xml 中有 android:id="@+id/list"
行.
Even though I have the android:id="@+id/list"
line in my xml.
有什么问题?
推荐答案
像这样重命名 ListView 的 id,
Rename the id of your ListView like this,
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
由于您使用 ListActivity
,您的 xml 文件必须在提及 ID 时指定关键字 android.
Since you are using ListActivity
your xml file must specify the keyword android while mentioning to a ID.
如果你需要一个自定义的 ListView
然后不是扩展一个 ListActivity
,你必须简单地扩展一个 Activity
并且应该有相同的 id没有关键字android.
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.
这篇关于您的内容必须有一个 id 属性为“android.R.id.list"的 ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!