2012-07-14 72 views
0

如果我在我的strings.xml文件中定义了一个字符串数组。默认情况下,字符串数组是否可以附加到ListView?

<string-array name="items"> 
    <item >item 1</item> 
    <item >item 2</item> 
    <item >item 3</item> 
</string-array> 

我可以使用引用将它直接插入我的ListView吗?

<ListView 
    android:id="@+id/itemsListView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    - reference to items here > 
</ListView> 

或者这是唯一可能的代码中使用适配器?

回答

2

从官方文档:

enter image description here

所以用你的ListView元素的android:entries属性,指着一个<string-array>资源[把你的数组放在res/values/arrays.xml]

但如果你有自定义您的项目(使用的ImageView,复选框......),你必须这样做以编程方式使用光标适配器或阵列适配器。

适配器均必须填写的ListView,GridView控件,画廊,微调等必须使用适配器

+0

酷谢谢,我现在把它的时间的数据源和UI组件之间的接口 – Spoonface 2012-07-14 22:18:26

2

使用android:entries的元素和refrences您<string-array>

,并创建(res->value->array.xml)

相关问题