Step 12

Now Run it!

You should now be able to add real notes from the menu, as well as delete an existing one. Notice that in order to delete, you must first use the directional controls on the device to highlight the note. Furthermore, selecting a note title from the list should bring up the note editor to let you edit it. Press confirm when finished to save the changes back to the database.

The current application has some problems — hitting the back button when editing causes a crash, and anything else that happens during editing will cause the edits to be lost.

To fix this, we will move most of the functionality for creating and editing the note into the NoteEdit class, and introduce a full life cycle for editing notes.

1. Remove the code in NoteEdit that parses the title and body from the extras Bundle.

Instead, we are going to use the DBHelper class to access the notes from the database directly. All we need passed into the NoteEdit Activity is a mRowId (but only if we are editing, if creating we pass nothing). Remove these lines:

String title = extras.getString(NotesDbAdapter.KEY_TITLE); String body = extras.getString(NotesDbAdapter.KEY BODY);

2. We will also get rid of the properties that were being passed in the extras Bundle, which we were using to set the title and body text edit values in the UI. So delete:



0 0

Post a comment