-
-
Save udacityandroid/266e8875e63b25d219f153ba72613ea9 to your computer and use it in GitHub Desktop.
@Override | |
public int delete(Uri uri, String selection, String[] selectionArgs) { | |
// Get writeable database | |
SQLiteDatabase database = mDbHelper.getWritableDatabase(); | |
final int match = sUriMatcher.match(uri); | |
switch (match) { | |
case PETS: | |
// Delete all rows that match the selection and selection args | |
return database.delete(PetEntry.TABLE_NAME, selection, selectionArgs); | |
case PET_ID: | |
// Delete a single row given by the ID in the URI | |
selection = PetEntry._ID + "=?"; | |
selectionArgs = new String[] { String.valueOf(ContentUris.parseId(uri)) }; | |
return database.delete(PetEntry.TABLE_NAME, selection, selectionArgs); | |
default: | |
throw new IllegalArgumentException("Deletion is not supported for " + uri); | |
} | |
} |
@udacityandroid I really love the way you teach Android. Best course I have ever taken!
Is it necessary to use final with variable match?
It is a better practice to use final with variables whose values we don't want to change in future.
The lesson https://classroom.udacity.com/courses/ud845/lessons/d3e97af7-7e35-40c2-8016-7dab121a3e39/concepts/530280d8-3659-4f8a-9e01-c50f543d92d3#
links to this gist instead of skeleton of the delete() method with TODO.
Yep wrong link 👍 Basically the solution is in the quiz!
I have a question:
What is the selection and selectionArgs if we wanted to delete the rows which they have the name "totti" and are male at the same time.
@Nikoloutsos I think it would be selection = name + "=? AND " + gender + "=?";
selectArgs[] = {"totti", "male"}
Yeah... I was like, "Ok... paste the gist.... ok.... uhm.... looks complete to me. What did I miss???? Did I just cheat?!?! Oh.... they gave us the answer." Well, crap, so much for trying on my own. LOL!
Your Task: Implement delete() method . . . . . . by cut 'n' paste, go on you can do it, I have faith in you 👍
you are right at mine all codes are now design by me