安卓:填充与数组项列表视图 [英] Android: Populating a listview with array items
问题描述
我是新来的Android,我想我试图做一些很基本的:我有一个5串在我的阵列(比如'一','二',...)。我想这5个字符串添加到我的listactivity我的列表视图。
I'm new to Android and I think I'm trying to do something really basic: I have a 5 strings in my Array (say 'One', 'Two', ...). I want to add these 5 strings to my list view in my listactivity.
我的清单:
<ListView
android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
我的列表行:
My List Row:
<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="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
基本上,我要绑定的数组项的TextView的homeItemName。我可以在我行添加其他物品后,所以我不能只绑定列表视图的条目。
Basically, I want to bind the Array items to the TextView homeItemName. I might add other items in my row later, so I can't just bind the listview to the entries.
谢谢!
推荐答案
有关code,采取快速看看这个<一href="http://developer.android.com/intl/de/resources/tutorials/views/hello-listview.html">step-by-step教程
For code, take a quick look at this step-by-step tutorial
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
ListView lv = getListView();
它显示了一个ArrayAdapter的基本实现:
It shows a basic implementation of an ArrayAdapter:
R.layout.list_item:是XML布局(list_item.xml),将用于每一行的 列表显示。 国家的字符串数组。
R.layout.list_item : is the xml layout (list_item.xml) that will be used for every ROW of your listview. COUNTRIES is the array of Strings.
这篇关于安卓:填充与数组项列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!