Instructions for using Menu.add () in Android

Source: Internet
Author: User

In Menu.add () there are four parameters, beginning to understand its rationale. Read the PostScript here for inspection.
The use of "menus" is indispensable for any software. Under Android, each activity is bundled with a menu, and to define and use the menus, it must be done under activity, using both the Oncreateoptionsmenu and onoptionsitemselected methods. Examples are as follows:


Java code:
@Override
public boolean Oncreateoptionsmenu (Menu menu) {


Method of the base class 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 the game"). SetIcon (R.drawable.info);

Menu.add (0,4,0, "Don't Want to Play"). SetIcon (R.drawable.exit);

If the icon is not displayed , change to Menu.add (0,3,0, "about Game");



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 group ID parameter of the first int type, which represents the concept of groups, allows you to group several menu items into groups to better manage your menu buttons in a group way.
The item ID parameter of the second int type, which represents the project number. This parameter is important, and an item ID corresponds to an option in the menu. Use this item ID to determine which option you are using when using the menu later.
The order ID parameter of the third int type, which represents the order in which the menu items are displayed. The default is 0, which means that the order in which the menus are displayed is displayed in the order in which they appear.
The title parameter of the fourth string type, which represents the text displayed in the option.

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.