Android learning notes (1)-menu operations

Source: Internet
Author: User
@ 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.