Step 10

Also remove the lines which set the title and body from the onListItemClick() method (again they are no longer needed, only the mRowId is):

Cursor c = mNotesCursor; c.moveToPosition(position);

and also remove:

i.putExtra(NotesDbAdapter.KEY_TITLE, c.getString(

c.getColumnIndex(NotesDbAdapter.KEY_TITLE))); i.putExtra(NotesDbAdapter.KEY_BODY, c.getString(

c.getColumnIndex(NotesDbAdapter.KEY_BODY)));

so that all that should be left in that method is:

super.onListItemClick(l, v, position, id); Intent i = new Intent(this, NoteEdit.class); i.putExtra(NotesDbAdapter.KEY_ROWID, id); startActivityForResult(i, ACTIVITY_EDIT);

You can also now remove the mNotesCursor field from the class, and set it back to using a local variable in the fillData() method:

Cursor notesCursor = mDbHelper.fetchAllNotes();

Note that the m in mNotesCursor denotes a member field, so when we make notesCursor a local variable, we drop the m. Remember to rename the other occurrences of mNotesCursor in yourfillData() method.

Run it! (use Run As -> Android Application on the project right click menu again)

Was this article helpful?

0 0

Post a comment