Android Db.delete(); On Listactivity
Solution 1:
By passing NULL as your second argument on this line:
db.delete(TabellaRegistry.TABLE_NAME,null, null);
You will always be deleting the whole table. As mentioned in the Android documentation, the parameters are as following:
public int delete (String table, String whereClause, String[] whereArgs)
table - the table to delete from
whereClause - the optional WHERE clause to apply when deleting. Passing null will delete all rows.
So let's say you want to delete the line where BOOK_ID is 6 you would have something like:
publicbooleandeleteTitle(String id)
{
return db.delete(DATABASE_TABLE, BOOK_ID + "=" + id, null) > 0;
}
SQLite Class Overview: http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
Solution 2:
In order to delete specific rows, you need to put a where clause in the delete statement delete
Solution 3:
If you check the api docs for this method you can get the answer yourself.
public intdelete (String table, String whereClause, String[] whereArgs)
Parameters
table the tabletodeletefrom
whereClause the optional WHERE clause to apply when deleting. Passing null will deleteall rows.
You are passing null in where clause which is the cause of deleting all records.
Post a Comment for "Android Db.delete(); On Listactivity"