2010-03-10 102 views
0

我試圖填充列表,我的問題是如何將列表行與多個項目綁定。到目前爲止,我有:Android:填充列表視圖行中的多個項目

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

home_item看起來是這樣的:

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

如果我添加其他的TextView說 「homeItemDec」,怎麼會我都homeItemName和homeItemDesc在我setListAdapter調用綁定?

回答

3

一旦您超越了基本列表項目,您可能想要開始製作自己的適配器並返回每個單元格的自定義視圖。代碼示例here

+0

同意,這是我想最終採取的方向。但是我想知道在學習更好的方法之前這樣做的最基本/最根本的方法......除非唯一的方法是通過創建我自己的適配器... – Prabhu 2010-03-11 17:40:04

+0

我還沒有看到默認的適配器,它可以做兩個文本視圖,而且你可能需要某種合理的佈局,否則只需連接就足夠了。所以你可能不得不製作一個自定義適配器,但它不是非常複雜,它給你很大的自由。 – jqpubliq 2010-03-11 20:54:42