0

タイプ の次の HashMap を作成し、次のようにHashMap<String, List<String>>値を追加しています。

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 に設定するにはどうすればよいですか?

4

1 に答える 1

0

次のコードを使用できます

ListAdapter adapter = new SimpleAdapter(this, hm , R.layout.listplaceholder, new String[] { "value1",
                "value2" }, new int[] { R.id.value1, R.id.name});
list.setAdapter(adapter);

listplaceholder私のxmlです。ですから、それを変更してください。

このチュートリアルに従うこともできます

于 2013-06-22T20:41:10.997 に答える