Android:填充列表视图行中的多个项目

问题描述:

我试图填充列表,我的问题是如何将列表行与多个项目绑定。到目前为止,我有: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调用绑定?

一旦您超越了基本列表项目,您可能想要开始制作自己的适配器并返回每个单元格的自定义视图。代码示例here

+0

同意,这是我想最终采取的方向。但是我想知道在学习更好的方法之前这样做的最基本/最根本的方法......除非唯一的方法是通过创建我自己的适配器... – Prabhu 2010-03-11 17:40:04

+0

我还没有看到默认的适配器,它可以做两个文本视图,而且你可能需要某种合理的布局,否则只需连接就足够了。所以你可能不得不制作一个自定义适配器,但它不是非常复杂,它给你很大的*。 – jqpubliq 2010-03-11 20:54:42