刪除記錄後,我無法刷新列表視圖。從列表視圖和數據庫中刪除和刷新項目
String str3 = favtitle.get(position);
//position = Integer.parseInt(cur.getString(cur.getColumnIndex("id")));
db.delete("Favorites7","title= '"+str3+"'",null);
//mSchedule.notifyDataSetChanged();
cur.requery();
cur= db.query("Favorites7",
null, null, null, null, null, null);
cur.moveToFirst();
while (cur.isAfterLast() == false) {
//name.append("n" + cur.getString(1));
//mylist.addAll(cur.getString(i));
favtitle.add(cur.getString(1));
favloc.add(cur.getString(3));
favemp.add(cur.getString(2));
lat.add(cur.getString(7));
log.add(cur.getString(8));
//nextScreenData.add(cur.getString(2).toString());
cur.moveToNext();
}
cur.close();
mylist = new ArrayList<HashMap<String,Object>>();
HashMap<String,Object> map = new HashMap<String, Object>();
for(int i=0;i<favtitle.size();i++)
{
map = new HashMap<String, Object>();
map.put("train",favtitle.get(i));
map.put("value",favloc.get(i));
map.put("employer",favemp.get(i));
mylist.add(map);
}
mSchedule.notifyDataSetChanged();
mSchedule = new SimpleAdapter(Favorites.this, mylist, R.layout.listdelete,
new String[] {"train","value","employer"}, new int[] {R.id.dept,R.id.jobloc,R.id.employer});
lv.setAdapter(mSchedule);
lv.setDividerHeight(2);
lv.setCacheColorHint(Color.WHITE);
//cur.requery();
Thanx提前。
我能夠刪除項目,但它不刷新.....它正在重新生成列表。當我回去再來時,它顯示已刪除項目的列表。我這樣做: – Piyush 2011-04-08 05:28:59
我編輯了我的問題請參閱...... – Piyush 2011-04-08 05:30:25
Mh,通常你的代碼應該工作,儘管你的概念用數據填充列表有點奇怪。爲什麼不使用SimpleCursorAdapter將光標直接綁定到列表? – Flo 2011-04-08 07:40:32