android中ListActivity使用记录Your content must have a ListView whose id attribute is 'android.R.id.l
16lz
2021-01-23
前几天在使用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 自定义控件
- 关于基本控件TextView属性大全详解
- Android Button控件 的简单使用(button监听和onClick触发函数使用
- adb错误:Failed to execute android command 'adb devices'.
- Android控件抖动效果
- Android瀑布流控件——AndroidStaggeredGrid
- 在Android当中常用的控件的详解和分析
- iOS和android解决键盘弹出遮挡控件的处理比较