在Java中,我如何引用一个给定了android:ID/list属性的列表?
在我的XML中,我有以下内容在Java中,我如何引用一个给定了android:ID/list属性的列表?,android,attributes,android-listview,Android,Attributes,Android Listview,在我的XML中,我有以下内容 <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="fill_parent" > </ListView> 如何在Java类文件中引用此列表视图。R.id.u似乎不起作用。试试这个id: android.R.id.list 谢谢斯卢金。我
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
</ListView>
如何在Java类文件中引用此列表视图。R.id.u似乎不起作用。试试这个id:
android.R.id.list
谢谢斯卢金。我想我会有进展的。但是为什么我现在不能调用android.R.id.list.getAdapter()。我试着从我在另一个帖子上问的另一个问题继续下去:再次感谢你。最后我终于明白了。要实际使用此列表执行任何操作,您需要通过执行ListView myListView=(ListView)findViewById(android.R.id.list)来实例化ListView//谢谢slukian,然后你想怎么做就怎么做。很确定这是最基本的东西,但在这里分享可能会让我这样的noob节省好几个小时。@Vim你不能调用
android.R.id.list.getAdapter()
因为android.R.id.list
它只是一个表示系统集id的整数。如果需要ListView
元素,则必须使用findViewById()
为该元素提供id来搜索布局(在您的例子中,ListView
的id是android.R.id.list
,因此您可以调用findviewbyd(android.R.id.list)
)。