in notepad/app/src/main/java/com/example/android/notepad/NotesList.java [151:174]
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info;
try {
info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
} catch (ClassCastException e) {
Log.e(TAG, "bad menuInfo", e);
return false;
}
Uri noteUri = ContentUris.withAppendedId(getIntent().getData(), info.id);
switch (item.getItemId()) {
case R.id.context_open:
// Launch activity to view/edit the currently selected item
startActivity(new Intent(Intent.ACTION_EDIT, noteUri));
return true;
case R.id.context_delete:
// Delete the note that the context menu is for
getContentResolver().delete(noteUri, null, null);
return true;
default:
return super.onContextItemSelected(item);
}
}