Step

Fill out the body of the onCreate() method.

Here we will set the title for the Activity (shown at the top of the screen), use the notepad list layout we created in XML, set up the NotesDbAdapter instance that will access notes data, and populate the list with the available note titles:

1. In the onCreate method, call super.onCreate() with the savedInstanceState parameter that's passed in.

2. Call setContentView() and pass R.layout.notepad list.

3. At the top of the class, create a new private class field called mDbHelper of class NotesDbAdapter.

4. Back in the onCreate method, construct a new NotesDbAdapter instance and assign it to the mDbHelper field (pass this into the constructor for DBHelper)

5. Call the open() method on mDbHelper to open (or create) the database.

6. Finally, call a new method fillData() , which will get the data and populate the ListView using the helper — we haven't defined this method yet.

onCreate() should now look like this:

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notepad list); mDbHelper = new NotesDbAdapter(this); mDbHelper.open(); fillData();

And be sure you have the mDbHelper field definition (right under the mNoteNumber definition):

private NotesDbAdapter mDbHelper;

0 0

Post a comment