github: T07.03-GetAllTheData , T07.04-UpdateTheAdapter , ,
Delete Guest:
// TODO (1) Create a new function called removeGuest that takes long id as input and returns a boolean public boolean removeGuest(Long id){ // TODO (2) Inside, call mDb.delete to pass in the TABLE_NAME and the condition that WaitlistEntry._ID equals id return mDb.delete(WaitlistContract.WaitlistEntry.TABLE_NAME, WaitlistContract.WaitlistEntry._ID+" = " +id, null) > 0; }
// TODO (6) Retrieve the id from the cursor and long id = mCursor.getLong(mCursor.getColumnIndex(WaitlistContract.WaitlistEntry._ID)); // TODO (7) Set the tag of the itemview in the holder to the id holder.itemView.setTag(id);
@Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { // TODO (8) Inside, get the viewHolder's itemView's tag and store in a long variable id //get the id of the item being swiped long id = (long) viewHolder.itemView.getTag(); // TODO (9) call removeGuest and pass through that id //remove from DB removeGuest(id); // TODO (10) call swapCursor on mAdapter passing in getAllGuests() as the argument //update the list mAdapter.swapCursor(getAllGuests()); }