android中ListActivity使用记录Your content must have a ListView whose id attribute is 'android.R.id.l
16lz
2021-12-29
前几天在使用Android的ListActivity过程中,发现不论怎么写,都会报错Your content must have a ListView whose id attribute is ‘android.R.id.list’
收到如下错误提示时错误定位在setContentView这一行
猜想可能是setContentView的资源文件里没找到一个id为list的ListView控件
<?xml version="1.0" encoding="utf-8"?><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控件
<?xml version="1.0" encoding="utf-8"?><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(安卓)Layout XML属性
- 关于基本控件TextView属性大全详解
- 第五课--位置布局
- Android(安卓)实用工具Hierarchy Viewer实战
- android:layout_alignParent 布局相对于父布局的位置
- Android中的常用控件之进度条(ProgressBar)
- Android(安卓)中自定义控件和属性(attr.xml,declare-styleable,T
- Android-x86-6.0定制之路 - 辛酸路开始