@ Overridepublic Boolean oncreateoptionsmenu (menu) {// todo auto-generated method stubmenu. add (0, 0, 0, "add memo"); menu. add (0, 1, 1, "delete all"); menu. add (0, 2, 2, "quit"); return Super. oncreateoptionsmenu (menu) ;}@ overridepublic Boolean onmenuitemselected (INT featureid, menuitem item) {// todo auto-generated method stubswitch (item. getitemid () {Case 0: // Add a memo system. out. println ("add data! "); // Adddata (); intent = new intent (noteactivity. this, edittime. class); intent. putextra ("click_key", "click_add"); startactivity (intent); break; Case 1: // Delete All deletetable (); setcontentview (R. layout. main); break; Case 2: // exit finish (); break; default: break;} return Super. onmenuitemselected (featureid, item );}
1. Parameters in the menu. Add method:
The Group ID parameter of the first int type represents the group concept. You can use the following methods:
Removegroup (ID)
Setgroupcheckable (ID, checkable, exclusive)
Setgroupenabled (ID, Boolean enabled)
Setgroupvisible (ID, visible)
Generally, it is 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 selected when you use 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 in the order of ADD.
The fourth string type title parameter, indicating the text displayed in the option.
2. Add images to menu:
The Code is as follows:
Menu. add (0, 2, 2, "add memo "). seticon (Android. r. drawable. ic_menu_add); menu. add (0, 3, 3, "delete all "). seticon (Android. r. drawable. ic_menu_delete); menu. add (0, 4, 4, "view history "). seticon (Android. r. drawable. ic_menu_recent_history); menu. add (0, 5, 5, "quit "). seticon (Android. r. drawable. ic_menu_close_clear_cancel );
The system image is called here. Of course, you can also customize your own image, which varies from person to person.