0
我有一個與listview有關係的數據庫適配器,當點擊列表項時,我有一個單擊監聽器,在數據庫之後刪除該項,該listivew重置爲0,但數據庫不..我需要知道,後刪除和我的清單中的項目如何在世界上我可以重置數據庫自動增量計數器的行ID返回1 ..其他listview和databse重新同步,其他的delete方法停止工作!這是問題驅使我瘋狂!請幫忙!如何重置Android中的數據庫行ID刪除後的0123返回1
//This is my code in the database adapter
public boolean deleteTask(long id){
return checklistDB.delete(DATABASE_TABLE, KEY_ROWID+ "=" + id, null) > 0;
}
//This is me calling the method in my activity
listview2.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
checklistDB.open();
//I add a counter to the position so that it equals the database row which starts at 1
arg2++;
checklistDB.deleteTask(arg2);
startActivity(new Intent("com.aondo.checklist.buslist"));
}
});
謝謝,我很感激。你介意顯示示例代碼我如何在我的適配器中的方法實現這一點,因爲即時通訊非常新的android。 – 2012-02-19 23:32:58
您需要將列表視圖從與本地存儲的關係改爲與項目列表建立關係。你還需要一個櫃檯來記住你所在的行號。在點擊函數中,不是調用一個刪除的函數,而是調用一個函數,將項目列表更新爲查詢內容......它看起來像這樣: myList = checklistDb.select( DATABASE_TABLE,「Limit」+ yourCounter「,null); 以下是關於Select的sqlite文檔,它教你關於limit子句:http://www.sqlite.org/lang_select.html – 2012-02-20 04:18:24