Skip to content Skip to sidebar Skip to footer

Android Db.delete(); On Listactivity

I need help on a matter... I created a listview with a cursord adapter that connects to my database,and shows me a list of everything that I saved in my table. I later created a c

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:

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"