My ListView shows data from my SQLITE Database.
By Longclick on a ListViewItem I delete this specific Item.
EveryThing works fine, but I don’t get my first item deleted. I don’t get any Errors in LogCat or something. Just nothing happens.
Here is my code from the Database class:
public void deleteEntry(String TABLE, int pos) {
SQLiteDatabase database = this.getWritableDatabase();
database.delete(TABLE, KEY_ROWID + "=?" , new String[] { String.valueOf(pos)});
// also tryed this code
database.delete(TABLE, KEY_ROWID + "= '" + pos +"'",null);
}
Here is the code of my ListView activity:
// Deletes the given row
database.deleteEntry(MyDatabase.DATABASE_TABLE_ORDERS, position);
updateList();
I’m quite shure that the committed int pos is representing the rowId of the respective Databse entry ( for the first entry pos is 0, for the second pos is 1 and so on )
updateList() creates a new listview and loads all the data from the DB again
Has anybody got an idea why i can delete all my Items in the ListView / rows in my DB besides my first entry? thx for your help!
After reading through your question a couple times I think what I initially posed in my comment is the issue…
It appears to me that you are using the
int posparameter and thinking that it is the row id in the DB, that is not the case. Theint posparameter is the position in the list (which can be different from the row id depending on your sort, etc).The row id is contained in the
long idparameter of the listener. The following changes should help you out (assuming my guess is correct).