所以基本上我有來自數據庫的記錄,每個記錄都有自己的唯一ID(主鍵)和日期(mm:hh mm/dd/yy),我想在應用程序的列表視圖中顯示這些記錄。但有時間(mm:hh)有點醜,所以我決定只在列表中顯示mm/dd/yy,現在的問題是,當我編寫onitemClick時,如何找出正在點擊哪個項目??因爲我沒有唯一的ID和確切的日期顯示在列表中了。如果項目名稱相同,如何找出列表中的哪個項目是點擊?
ArrayList<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for (int x = Records.size()-1; x >=0; x--)
{
map = new HashMap<String, String>();
map.put("ID", String.valueOf(Records.get(x).getId()));
map.put("date", Records.get(x).getDate()); //I am going to change this date to just mm/dd/yy
aList.add(map);
}
sd = new SimpleAdapter(this, aList, R.layout.historyactivityrow,
new String[]
{ "date" }, new int[]
{ R.id.date });
lv.setAdapter(sd);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3)
{
TextView tx = (TextView) view.findViewById(R.id.date);
String s = tx.getText().toString();
Intent intent = new Intent(HistoryActivity.this, EditRecordActivity.class);
intent.putExtra("date", s); //I can't do this anymore because now the EditRecordActivity will not know the exact record to be edited.
startActivity(intent);
}
});
請幫忙。
你是對的!非常感謝 – 2012-08-08 22:12:06