我有一个列表视图中有三个项目。 color_id
,color_name
和color_count
如何摆脱SimpleAdapter
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/color_id"/>
<TextView android:id="@+id/color_name"/>
<TextView android:id="@+id/color_count"/>
</LinearLayout>
我加载数据从服务器到我的名单。在这里,我手动将数据添加到列表中示范:
ArrayList<HashMap<String, String>> colorsList = new ArrayList();
HashMap<String, String> map = new HashMap();
map.put("id", "1");
map.put("color_name", "red");
map.put("color_count", "10");
colorsList.add(map);
map = new HashMap();
map.put("id", "2");
map.put("color_name","yellow"):
map.put("color_count","15");
colorsList.add(map);
ListAdapter adapter = new SimpleAdapter(
MyActivity.this, colorsList,
R.layout.list_item_colors, new String[] {"id",
"color_name","color_count"}, new int[] {
R.id.color_id, R.id.color_name, R.id.color_count});
setListAdapter(adapter);
问题
所有这一切都为我工作的罚款。但是,对于其他原因,我想分手了SimpleAdapter
方式,而使用ArrayAdapter
然而,随着ArrayAdapter
我不知道如何设置的三个项目我有:color_id
,color_name
和color_count
你想用自定义ListView和ArrayAdapter来保存textviews? –
是的。我有ListView中有多个textviews,我不想使用SimpleAdapter。 – birdy