【发布时间】:2013-06-22 20:14:30
【问题描述】:
我创建了以下 HashMap<String, List<String>> 类型的 HashMap,并正在为其添加值,如下所示:
ListView lv = (ListView)findViewById(R.id.list);
HashMap<String, List<String>> hm = new HashMap<String, List<String>>();
List<String> values = new ArrayList<String>();
for (int i = 0; i < j; i++) {
values.add(value1);
values.add(value2);
hm.put(key, values);
}
我想检索数据,将其解析为 ListAdapter,然后解析为 ListView。这是列表视图的 xml:
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
以及列表项的 xml:
<!-- for the key value -->
<TextView
android:id="@+id/id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<!-- For Value 1 -->
<TextView
android:id="@+id/value1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<!-- For Value 2 -->
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
如何从 hashMap 中检索数据,将其放入 ListAdapter,然后将其设置到 ListView?
【问题讨论】: