我有一个listview,只需这样填充:
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, aux))
'aux'它是static String[] aux = null;
,它通过Web服务填充。
我创建了一个主题并使用静态listview元素进行测试,文件lista.xml - &gt;你可以看到它here(如果你看到底部,你会看到我把“列表项1,列表项2”,所以我需要在dinamically中填充这些值...)
我的问题是,如何将主题应用于listadapter?
我相信我从:
开始setListAdapter(new ArrayAdapter(this, R.layout.lista,aux))
但我有两个问题。
(1)我不知道如何使用XML并从java填充(setlistadapter) (2)我相信我会失去复选框。
但是我很感激,如果有人可以帮助(1)首先:)我真的不知道现在在做什么!
答案 0 :(得分:1)
setListAdapter(new ArrayAdapter(this, R.layout.lista, aux))
是开始,你是对的,但是当你想要一个自定义ListItem布局时,你必须编写一个自定义ListAdapter。你以extend ArrayAdapter<YourItemClass>
为例。在那里,您可以覆盖方法getView()
,在此方法中,您可以使用辅助对象的值填充自定义布局。
对于ArrayAdapter,您必须在布局中为列表视图项设置一个ID
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/textview" android:layout_weight="1">
</TextView>
使用id / textview,您可以将listAdapter渲染到此视图中。
编辑:哦,你必须学习并遵守列表的持有人概念。在这里:How to load the Listview "smoothly" in android