Sunday 23 September 2012

android: Dynamic Menus with out XML


private static final int MENU_EDITLIST = 0;
private static final int MENU_HELP = 1;
private static final int MENU_ABOUT = 2;


public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_EDITLIST, 0, "Edit List").setIcon(
R.drawable.ic_launcher);
menu.add(0, MENU_HELP, 0, "Help").setIcon(R.drawable.ic_launcher);
menu.add(0, MENU_ABOUT, 0, "About us").setIcon(R.drawable.ic_launcher);
return true;
}


public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case MENU_EDITLIST:
Intent intent1 = new Intent(this, Help.class);
startActivity(intent1);
return true;
case MENU_HELP:
Intent intent1 = new Intent(this, Help.class);
startActivity(intent1);
return true;
case MENU_ABOUT:
Intent intent2 = new Intent(this, About.class);
startActivity(intent2);
return true;
default:
return super.onOptionsItemSelected(item);
}
}


No comments:

Post a Comment