in notepad/app/src/main/java/com/example/android/notepad/NotesList.java [59:83]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
// If no data was given in the intent (because we were started
// as a MAIN activity), then use our default content provider.
Intent intent = getIntent();
if (intent.getData() == null) {
intent.setData(NoteColumns.CONTENT_URI);
}
// Inform the list we provide context menus for items
getListView().setOnCreateContextMenuListener(this);
// Perform a managed query. The Activity will handle closing and requerying the cursor
// when needed.
Cursor cursor = managedQuery(getIntent().getData(), PROJECTION, null, null,
NoteColumns.DEFAULT_SORT_ORDER);
// Used to map notes entries from the database to views
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.noteslist_item, cursor,
new String[] { NoteColumns.TITLE }, new int[] { android.R.id.text1 });
setListAdapter(adapter);
}