android中ListActivity使用记录Your content must have a ListView whose id attribute is 'android.R.id.list'

前几天在使用Android的ListActivity过程中,发现不论怎么写,都会报错Your content must have a ListView whose id attribute is ‘android.R.id.list’

收到如下错误提示时错误定位在setContentView这一行

猜想可能是setContentView的资源文件里没找到一个id为list的ListView控件


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <ListView
        android:layout_width="match_parent"
        android:id="@+id/list"
        android:layoutAnimation="@anim/list_anim"
        android:layout_height="match_parent"/>
LinearLayout>

然而在运行的时候还是报了同样的错误,再仔细看错误提示
发现需要的是一个id为’android.R.id.list’的ListView控件


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layoutAnimation="@anim/list_anim"
        android:id="@android:id/list">ListView>
LinearLayout>

最终程序完美运行

你可能感兴趣的:(Android,android,编辑器,listview,控件)