Android has a couple menu types. The “option” menu is one that is access by using the unit’s menu button. Since it is built into the view, you only need to
The setup – some constants:
final public int MENU_GROUP=0;
final public int MENU_ADD=0;
final public int MENU_EDIT=1;
final public int MENU_DELETE=2;
The setup – build the list
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(MENU_GROUP, MENU_ADD, 0, "add");
menu.add(MENU_GROUP, MENU_EDIT, 0, "edit");
menu.add(MENU_GROUP, MENU_DELETE, 0, "delete");
return super.onCreateOptionsMenu(menu);
}
The handler – respond to the options
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case MENU_ADD:
Intent intent = new Intent(getBaseContext(), editActivity.class);
intent.putExtra("ID", 0);
startActivity(intent);
return true;
case MENU_EDIT:
return true;
case MENU_DELETE:
return true;
}
return super.onOptionsItemSelected(item);
}