Add and Handle Menu Items
public class TestProject extends Activity {
/* Set ID's */
private final int MENU_NEW_GAME = 0;
private final int MENU_QUIT = 1;
/* Create Menu Items */
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_NEW_GAME, 0, "Help");
menu.add(0, MENU_QUIT, 0, "About");
return true;
}
/* Handles Item Selection */
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_NEW_GAME:
newGame();
return true;
case MENU_QUIT:
finish();
return true;
}
return false;
}
}
/* Set ID's */
private final int MENU_NEW_GAME = 0;
private final int MENU_QUIT = 1;
/* Create Menu Items */
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_NEW_GAME, 0, "Help");
menu.add(0, MENU_QUIT, 0, "About");
return true;
}
/* Handles Item Selection */
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_NEW_GAME:
newGame();
return true;
case MENU_QUIT:
finish();
return true;
}
return false;
}
}
Comments
Post a Comment