ArrayList<HashMap<String, String>> historyArrayList;
SimpleAdapter histroyListAdapter;
HashMap<String, String> historyObjectMap;
for (CheckInCheckOutHistory checkOutHistoryObj : checkInCheckOutHistoryList) {
historyObjectMap = new HashMap<String, String>();
historyObjectMap.put("assetTag", checkOutHistoryObj.getAssetTag());
historyObjectMap.put("action", checkOutHistoryObj.getAction());
historyObjectMap.put("actionTime", checkOutHistoryObj.getActionDate());
if (checkOutHistoryObj.getAction().equals("Checked out")) {
historyObjectMap.put("gif", R.drawable.radio_button_yellow+ "");
} else {
historyObjectMap.put("gif", R.drawable.radio_button_green+ "");
}
historyArrayList.add(historyObjectMap);
}
histroyListAdapter = new SimpleAdapter(
ViewCheckInCheckOutHistory.this, historyArrayList,
R.layout.multi_colummn_list_text_style_small, new String[] {
"assetTag", "gif" , "action", "actionTime"},
new int[] { R.id.list_content_column1,
R.id.list_content_imagecolumn,
R.id.list_content_column3,
R.id.list_content_column4});
historyListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
HashMap<String, String> historyObjectMapLocal = historyArrayList
.get(position);
final String assetTag = historyObjectMapLocal
.get("assetTag");
System.out.println("assetTag : " + assetTag);
}
});
在上面的代碼ListView的內容是使用一個ArrayList historyArrayList 並因此在任何列中的項目可以使用鍵來訪問(「ASSETTAG填充「,」gif「,」動作「,」動作時間「)。
來源
2011-08-10 11:45:40
Ian
我正在使用'SimpleAdapter' – Piraba
所以你已經將一個HashMap提供給ListView?您將獲得HashMap hashMap =(HashMap )listView.getItemAtPosition(position);那時候。 –
這是正確答案。謝謝它的正常工作 – Piraba