【发布时间】:2014-10-21 09:08:09
【问题描述】:
我正在尝试在同一布局中的两个列表视图上设置两个不同的适配器。在互联网上进行了几次搜索并且这个错误“必须有一个列表视图,其 id 必须是 android.R.id.list”后,我发现我需要将我的列表视图 id 定义为@android:id/list。
我想知道如何引用使用@android:id/list 的两个不同的列表视图?
下面的代码有意义吗?
ListView lv1 = (ListView) findViewById(android.R.id.list);
ListView lv2 = (ListView) findViewById(android.R.id.list);
ps:我正在使用 Fragment 并扩展 ListFragment。
【问题讨论】:
-
在 xml 文件中给出不同的 id
-
您必须为此使用自定义适配器。在这种情况下,您无需使用此 id,并且可以用任何东西更改名称。但问题是,你为什么需要它?
-
I am working in a Fragment and extending ListFragment.这就是问题所在。您最好扩展 Fragment(包含两个具有不同 id 的 ListView),而不是 ListFragment。 OR 使用 2 个不同的 ListFragment,每个都包含自己的 ListView。如您所知,一个 Activity 可以包含多个 Fragment(或派生类)。 -
@Funkystein,谢谢。现在它起作用了。 :)
标签: android android-layout android-listview android-xml android-listfragment