views:

255

answers:

1

I'm trying to populate a list, and my question is how do you bind the list row with multiple items. So far I have:

String[] homeLists = getResources().getStringArray(R.array.homeItems); 
setListAdapter(new ArrayAdapter<String>(this, R.layout.home_item, R.id.homeItemName, homeLists));

home_item looks like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
<TextView android:id="@+id/homeItemName" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp"/>

If I add another TextView say "homeItemDec", how will I bind both homeItemName and homeItemDesc in my setListAdapter call?

+1  A: 

Once you get beyond a basic list item, you probably want to start making your own adapter and returning a custom view for each cell. Code sample here

jqpubliq
Agreed, that's the direction I want to eventually take. But I'd like to know the most basic/fundamental way of doing this before learning the better way to do this...unless the only way to do this is by creating my own adapter...
Prabhu
I haven't seen a default adapter that does two textviews, and you probably want some sort of reasonable layout, otherwise just concatenation should be enough. So you probably will have to make a custom adapter, but its not super complicated and it gives you a lot of freedom.
jqpubliq