The use of menus is indispensable for any software. In Android, each activity is bound with a menu. To define and use a menu, you must perform operations under the activity and rewrite the oncreateoptionsmenu and onoptionsitemselected methods. Example:
@ Override
Public Boolean oncreateoptionsmenu (menu ){
// Use the base class method to bring up the system menu (if any)
Super. oncreateoptionsmenu (menu );
Menu. Add (0, 1, 0, "Start again"). seticon (R. drawable. reflash );
Menu. Add (0, 2, 0, "game guide"). seticon (R. drawable. Help );
Menu. Add (0, 3, 0, "about games"). seticon (r.drawable.info );
Menu. Add (, 0, "don't want to play"). seticon (R. drawable. Exit );
// The return value is "true", indicating that the menu is visible, that is, the menu is displayed.
Return true;
}
Take a look at the parameters of the menu. Add method:
The first int type group ID parameter represents the group concept. You can group several menu items to better manage your menu buttons in a group.
The item ID parameter of the second int type represents the project number. This parameter is very important. An item ID corresponds to an option in a menu. This item ID is used to determine which option you are using when using the menu later.
The third 'order id' parameter of 'int' type represents the order in which menu items are displayed. The default value is 0, indicating that the display order of the menu is displayed according to the display order of ADD.
The fourth string type title parameter, indicating the text displayed in the option.
Let's take a look at the seticon method, which is to add the icon display for the menu and use the resource source file.
After the menu is designed, continue to rewrite the onoptionsitemselected method to respond to the menu. Sample Code:
@ Override
Public Boolean onoptionsitemselected (menuitem item ){
Super. onoptionsitemselecte (item );
Switch (item. getitemid ()){
Case1:
// Process the code
Case2:
// Process the code
Case: 3
// Process the code
Case: 4
Finish ();
Break;
}
Return true;
}
Http://dev.10086.cn/cmdn/supesite? 2515124/viewspace-36169