データベース クエリからリストビュー (項目ごとに 2 行) を作成しています。各アイテムにいくつかのデータを添付していますが、後で onClick リスナーで再度取得するのに問題があります。
dataはキーと値のペアのリストです。たとえば、タイトル、日付、および ID です。
List<Map<String, String>> data = new ArrayList<Map<String, String>>();
次のようなリストビューを作成するアダプター:
SimpleAdapter adapter = new SimpleAdapter(this, data,
android.R.layout.simple_list_item_2,
new String[] {"title", "date"},
new int[] {android.R.id.text1, android.R.id.text2});
itemlist.setAdapter(adapter);
setListAdapter(adapter);
私は onListItemClick リスナーを次のようにアタッチしています:
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(this, CtestActivity.class);
Object obj = this.getListAdapter().getItem(position);
// here I want to extract the id from obj
// obj.toString() is {id:7, title: sometitle, date: yesterday}
}
これは単純に、Java の知識が不足している可能性があります。いずれにせよ、この「マップのような」オブジェクト obj から特定の値にアクセスする方法についての情報をいただければ幸いです。