我做了一個listView與自定義適配器它從數據庫獲取數據並將其綁定到列表視圖,適配器選取記錄數很好,但它不斷顯示所有條目的最後記錄,例如如果有5條記錄從數據庫檢索列表視圖將顯示五次最後一個記錄。ListView重複最後一個條目
這裏是代碼
Activities SetAct = new Activities();
final ArrayList<Activities> sData = new ArrayList<Activities>();
try{
SQLiteDatabase db = openOrCreateDatabase("iTimeDB", MODE_PRIVATE, null);
Cursor c2 = db.rawQuery("SELECT * FROM Activities", null); // WHERE ID = '" +ID+"'"
for (c2.moveToFirst(); !c2.isAfterLast(); c2.moveToNext()) {
String title =c2.getString(c2.getColumnIndex("Title"));
String details =c2.getString(c2.getColumnIndex("Details"));
String time =c2.getString(c2.getColumnIndex("Time"));
String ref= c2.getString(c2.getColumnIndex("Ref"));
String matter =c2.getString(c2.getColumnIndex("Matter"));
String date = c2.getString(c2.getColumnIndex("Date"));
String ID = c2.getString(c2.getColumnIndex("ID"));
String IMEI1 = c2.getString(c2.getColumnIndex("IMEI"));
SetAct.setTitle(title);
SetAct.setDetails(details);
SetAct.setMatter(matter);
SetAct.setRef(ref);
SetAct.setTime(time);
SetAct.setDate(date);
SetAct.setID(ID);
sData.add(SetAct);
}
c2.close();
db.close();
}
catch(Exception e){
e.printStackTrace();
Log.v("YYY", e.toString());
}
final ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new CustomListAdapter(this, sData));
感謝擴展類,,它的工作:-) –
@AdilWaqar高興它幫助請接受我答。 – Hariharan