I just tried to implement SQLite database thing in my Android App. Maybe I am not getting everything perfectly at Android developer Guide, So, I just found a nice tutorial on web, from this website.
Moreover, I just understood everything I need and implementing well until the DELETION operation.
From that above mentioned website code, I have this code to delete single user:
// Deleting single contact
public static void deleteUserData(UserData data) {
final SQLiteDatabase db = open();
db.delete(USER_TABLE, KEY_ID + " = ?",
new String[] { String.valueOf(data.getID()) });
db.close();
}
In my Application i am getting text from Edittext and retrieving it and showing it on the ListView. Also implemented "listItem.onItemLongClickListener()" to delete an item from the ListView, as shown below:
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
long arg3) {
//UserData dataView = new UserData();
//DBAdapter.deleteUserData(dataView);
allData.remove(position);
adapter.notifyDataSetChanged();
return false;
}
I am not able to understand how to pass the correct argument to the deleteUserData(UserData data) method.
My problem here is How to delete single item and set the autoincremented primary key value accordingly.
P.S : Please refer to the above link for complete code reference in that site.
Thanks.