您的内容必须具有一个ListView,其id属性为‘android.R.id.list’。

您的内容必须具有一个ListView,其id属性为‘android.R.id.list’。

我创建了这样一个XML文件:

<?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);
    }}

如你所见,我什么也没做。但我发现了一个错误:

您的内容必须具有一个ListView,其id属性为‘android.R.id.list’。

即使我有android:id="@+id/list"XML中的行。

有什么问题吗?


守着一只汪
浏览 593回答 3
3回答

肥皂起泡泡

将ListView的id重命名如下<ListView&nbsp;android:id="@android:id/list" &nbsp;&nbsp;&nbsp;&nbsp;android:layout_width="fill_parent" &nbsp;&nbsp;&nbsp;&nbsp;android:layout_height="fill_parent"/>因为你用ListActivity您的xml文件必须指定关键字。安卓同时提到了一个ID。如果你需要定制ListView然后,而不是扩展ListActivity,您必须简单地扩展Activity,并且应该具有相同的id而不带关键字。安卓.

弑天下

您应该在您的mainlist.xml以id作为@android:id/list<ListView &nbsp;&nbsp;&nbsp;&nbsp;android:id="@android:id/list" &nbsp;&nbsp;&nbsp;&nbsp;android:layout_height="wrap_content" &nbsp;&nbsp;&nbsp;&nbsp;android:layout_height="fill_parent"/>

芜湖不芜

<ListView&nbsp;android:id="@android:id/list" &nbsp;&nbsp;&nbsp;&nbsp;android:layout_width="fill_parent" &nbsp;&nbsp;&nbsp;&nbsp;android:layout_height="fill_parent"/>这应该能解决你的问题
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android