开发者

How to set a theme to a Listview populated with setListAdapter

I have a listview which is simply populated this way:

setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_multiple_choice, aux))

'aux' it's static String[] aux = null;which is populated via Web Service.

I made a theme and tested with static listview elements, file lista.xml -> you can see it here (if you look in the bottom you will see I put "list item 1, list item 2", so I need to populate those values dinamically...)

My question is, how can I apply the theme to my listadapt开发者_C百科er?

I believe I start with :

setListAdapter(new ArrayAdapter(this, R.layout.lista, aux))

But I have two problems.

(1) I dont know how to work with XML and populating from java (setlistadapter) (2) I believe I will lose checkboxes.

However I appreciate if anyone can help in (1) first :) I really don't know what am doing now!


setListAdapter(new ArrayAdapter(this, R.layout.lista, aux))

is the start, you are right, but when you want a custom ListItem Layout you have to write a custom ListAdapter. You extend ArrayAdapter<YourItemClass> for example. There you override the method getView() and in this method you populate your custom Layout with your Values of your Aux Objects.

for an ArrayAdapter you have to set a id in your layout for your listview items

<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>

with id/textview you say your listAdapter to render into this View.

edit: oh and you have to learn and obey the holder concept of Lists. here: How to load the Listview "smoothly" in android

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜