用menu要用到覆盖两个方法:
public static final int USE_MENU = Menu.FIRST;
private static final int HELP_MENU = Menu.FIRST+1;
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
super.onOptionsItemSelected(item);
Intent intent = new Intent();
switch(item.getItemId()){
case USE_MENU:
intent.setClass(ActivityMain.this, Auth.class);
startActivity(intent);
break;
case HELP_MENU:
intent.setClass(ActivityMain.this, Help.class);
break;
}
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
menu.add(0, USE_MENU, 0, R.string.start_use)
.setAlphabeticShortcut('S')
.setIcon(R.drawable.menu_start);
menu.add(0, HELP_MENU, 1, R.string.help)
.setAlphabeticShortcut('H')
.setIcon(R.drawable.helps);
return true;
}
public static final int USE_MENU = Menu.FIRST;
private static final int HELP_MENU = Menu.FIRST+1;
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
super.onOptionsItemSelected(item);
Intent intent = new Intent();
switch(item.getItemId()){
case USE_MENU:
intent.setClass(ActivityMain.this, Auth.class);
startActivity(intent);
break;
case HELP_MENU:
intent.setClass(ActivityMain.this, Help.class);
break;
}
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
menu.add(0, USE_MENU, 0, R.string.start_use)
.setAlphabeticShortcut('S')
.setIcon(R.drawable.menu_start);
menu.add(0, HELP_MENU, 1, R.string.help)
.setAlphabeticShortcut('H')
.setIcon(R.drawable.helps);
return true;
}