我有一個SQLite數據庫是這樣的:的Android SQLite的decremente ID
private static final String CREATE_BDD =
"CREATE TABLE " + TABLE_NOTE + " ("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COL_TITLE + " TEXT NOT NULL, "
+ COL_NOTE + " TEXT NOT NULL, "
+ COL_COLOR + " TEXT NOT NULL);";
數據庫存儲注意到,我可以通過ID來識別。當我從數據庫中刪除一個筆記時,我希望所有的ID高於所刪除的筆記的ID減1,那麼我可以保持列ID爲「1,2,3,4」而不是「1,3,4」當我刪除注意到ID 2.
因爲我用它來閱讀我的所有筆記(與BDDManager我DAO),我想不使用列表來獲取所有的筆記:
private void readAllNotes(){
int i = 1;
Note note = new Note();
BDDManager.open();
do{
note = BDDManager.getNoteWithId(i);
if(note != null){
addCard(note); //here I add the note to a new TextView
i++;
}
}while(note != null);
BDDManager.close();
}
而且當我刪除筆記後,我無法閱讀刪除的ID後,因爲它返回空並停止讀取筆記後刪除筆記
這是我如何刪除筆記:
public int removeNoteWithId(int id){
return bdd.delete(TABLE_NOTE, COL_ID + " = " +id, null);
}