The following is the first few sections of a chapter from Exploring Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Adding and Deleting Items

Now, we can edit our to-do items. However, the app is still pretty limited, in that we can only have exactly three to-do items. While we can now change what appears in those to-do items, we cannot add or remove any.

We really should fix that.

So, in this tutorial, we will wrap up the “glassware” portion of the app, by getting rid of the fake starter data and giving the user the ability to add new to-do items and delete existing ones.

This is a continuation of the work we did in the previous tutorial. The book’s GitHub repository contains the results of the previous tutorial as well as the results of completing the work in this tutorial.

Step #1: Removing the Sample Data

In ToDoRepository, remove the constructor, which is where we were setting up the fake data.

If you now run the sample app, it runs, but we have no to-do items:

ToDo App, Showing Nothing
Figure 167: ToDo App, Showing Nothing

Step #2: Showing an Empty View

The preview of this section may contain nuts.

Step #3: Adding an Add Action Bar Item

The preview of this section left for Hollywood to appear in a reality TV show.

Step #4: Launching the EditFragment for Adds

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

Step #5: Adjusting Our Save Logic

The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.

Step #6: Hiding the Empty View

The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).

Step #7: Adding a Delete Action Bar Item

The preview of this section was lost in the sofa cushions.

Step #8: Deleting the Item

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

Step #9: Fixing the Delete-on-Add Problem

The preview of this section is in an invisible, microscopic font.

Step #10: Fix Our Tests

The preview of this section was fed to a gremlin, after midnight.

What We Changed

The preview of this section is in an invisible, microscopic font.