Add/ Delete/ Update Data –> SQLite Database

github: T07.03-GetAllTheData , T07.04-UpdateTheAdapter , T07.05-AddGuests , T7.06-RemoveGuests

img_20170927_224322.jpg

 

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());
}

Add Guest:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s