Android Your content must have a ListView whose...
16lz
2021-01-23
Android Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法
在Android开发中,ListView有着很重要的地位,使用的场合也非常的多
错误提示:Your content must have a ListView whose id attribute is 'android.R.id.list'
对于以上错误,其实可能是因为我们要实现对ListView中setOnItemClick的事件监听而去继承了LiseActivity,但是却没有ListView的标签,网上有说过只要在布局文件中添加如下代码即可:
- <ListView
- a<ListView android:id="@android :id/list" 或android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content"> </ListView>
ndroid:id="@android :id/list" 或android:id="@id/android:list" - android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </ListView>
但是如果我们是为了实现自定义的ListView,也就是我们后面是通过在BaseAdapter中实现对ListView中空间的监听,那我们这边就只要继承Activity就可以了的。但是注意,我们用的是ListView,又没有去继承ListActivity,因此,一定要记得在工程中声明一个ListView对象并对其进行实例化,这样可以得到要的ListView了
不用着急哈,不要忘了我们还有自己实例化的那个ListView哈,有了这个就可以通过这个调用setOnItemClickListener方法喽~具体如下:
- listView.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
- long arg3) {
- // TODO Auto-generated method stub
- Log.i("TAG","The Item has been clicked");
- }
- });
而这个时候我们也就依然能像之前介绍的那样用与系统提供的SimpleAdapter提供的一样的构造方法来调用我们自己自定义的BaseAdapter喽
更多相关文章
- Android Permission denied 错误(附Android权限大全)
- Android Activity切换动画详解及实例
- Android Permission denied 错误 ( 附Android权限大全 )
- android实现开机自动播放音乐实例(Broadcast、Service)
- android install faild insufficient storage错误的解决方法
- Android错误处理——Android读取txt文件乱码解决方案
- Android开发:观察者模式应用实例
- Android常见错误(http://www.cnblogs.com/ok-lanyan/archive/2011