您的内容必须具有ListView,其id属性为'android.R.id.list'
我创建了一个像这样的xml文件:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list" >
和一项活动:
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'
即使我的xml中有android:id="@+id/list"行。
问题是什么?
7个解决方案
327 votes
像这样重命名ListView的id,
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
由于您使用的是ListView,因此您的xml文件必须在提及ID时指定关键字android。
如果你需要自定义ListView然后而不是扩展ListActivity,你必须简单地扩展Activity并且应该具有相同的id而没有关键字android。
Andro Selva answered 2019-05-17T01:04:11Z
23 votes
你应该在mainlist.xml文件中有一个列表视图,ID为@android:id/list
android:id="@android:id/list"
android:layout_height="wrap_content"
android:layout_height="fill_parent"/>
Praveenkumar answered 2019-05-17T01:04:36Z
15 votes
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
这应该可以解决你的问题
Aamirkhan answered 2019-05-17T01:05:00Z
6 votes
确切的方法我根据上面的反馈修复了这个问题,因为我最初无法让它工作:
activity_main.xml中:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list"
>
MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addPreferencesFromResource(R.xml.preferences);
的preferences.xml:
android:key="upgradecategory"
android:title="Upgrade" >
android:key="download"
android:title="Get OnCall Pager Pro"
android:summary="Touch to download the Pro Version!" />
Kevin answered 2019-05-17T01:05:41Z
3 votes
继承Activity类而不是ListActivity可以解决此问题。
public class ExampleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlist);
}
}
Vicky answered 2019-05-17T01:06:06Z
1 votes
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbars="vertical"/>
Makvin answered 2019-05-17T01:06:24Z
0 votes
另一件影响我的事情:如果您有多个测试设备,请确保您正在更改设备使用的布局。 在我的情况下,我花了一些时间在“布局”目录中对xmls进行了更改,直到我发现我的大手机(我切换到测试的中途)在“layout-sw360dp”目录中使用了xmls。哎呀!
RudyF answered 2019-05-17T01:06:50Z