私はSimpleAdapterを使ってListViewを埋めようとしましたが、失敗しただけです。Android:ListViewとSimpleAdapterについて
多くのケースを読んだことがありますが、それでも便利な方法はありません。
ここにコードがあります。私は何が問題なのだろうか。
ArrayList<HashMap<String,Object>> listdata=new ArrayList<HashMap<String,Object>>();
for (int i=0;i<3;i++){
HashMap<String, Object> hm = new HashMap<String, Object>();
hm.put("title", "title");
hm.put("context", "context");
listdata.add(hm);
}
String[] from = {"title", "context"};
int[] to={R.id.title,R.id.context};
SimpleAdapter adapter = new SimpleAdapter(this, listdata, R.layout.list_item, from, to);
ListView lv=(ListView)this.findViewById(R.id.listView1);
lv.setAdapter(adapter);
list_item
<LinearLayout
<ListView android:layout_height="wrap_content" android:id="@+id/listV1" android:layout_width="match_parent">
<LinearLayout>
<TextView android:layout_height="wrap_content" android:id="@+id/title" android:text="TextView" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<TextView android:text="TextView" android:id="@+id/context" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
</ListView>
ための//コード誰でも助けることができる場合、私は感謝します!
2つのレイアウトファイルで質問を更新できますか?投稿したXMLが不適切なカット&ペーストに見える – Rob
例外を投稿することはできますか? – Jack