Step 6

Define the populateFields() method.

private void populateFields() { if (mRowId != null) {

Cursor note = mDbHelper.fetchNote(mRowId);



note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE))); mBodyText.setText(note.getString(


This method uses the NotesDbAdapter.fetchNote() method to find the right note to edit, then it calls startManagingCursor() from the Activity class, which is an Android convenience method provided to take care of the Cursor life-cycle. This will release and re-create resources as dictated by the Activity life-cycle, so we don't need to worry about doing that ourselves. After that, we just look up the title and body values from the Cursor and populate the View elements with them.

0 0

Post a comment