Android menu items

Source: Internet
Author: User
As you are familiar with, Android supports most traditional menu options, including icon, shortcut, checkbox, and radio button, as described below: checkboxes and Radio buttonscheckboxes and radio buttons are visible in the extended menu and sub-menu, as shown in 4-6. Set the menu item to checkbox and use the setcheckable method. The status of the checkbox is controlled by the setchecked method. A radio button group is a set of buttons that show the cycle selection. Only one project can be selected at a time. In the same group, if one is selected, the other will automatically become unselected. To create a radio button group, you must specify the same group ID for each project, call the menu. setgroupcheckable method, input the group ID, and specify other parameters as true. Checkbox is not visible in the icon menu. Therefore, the menu items that are represented as checkbox should be reserved for sub-menus and extended menus. The following Code The snippet shows how to add a checkbox and a group of three radio buttons: // create a new check box item. menu. add (0, checkbox_item, menu. none, "checkbox "). setcheckable (true); // create a radio button group. menu. add (rb_group, radiobutton_1, menu. none, "radiobutton 1"); menu. add (rb_group, radiobutton_2, menu. none, "radiobutton 2"); menu. add (rb_group, radiobutton_3, menu. none, "radiobutton 3 "). setchecked (true); menu. setgroupcheckable (rb_gr OUP, true, true); you can use the setshortcut method to specify shortcuts for menu items. Each call to setshortcut requires two Shortcut Keys: one is the number key and the other can be the keys in the entire keyboard. Any key is case insensitive. The following code snippet shows how to set shortcuts for two modes: // Add a shortcut cut to this menu item, '0' if using the numeric keypad // or 'B' if using the full keyboard. menuitem. setshortcut ('0', 'B'); the condensed titles Icon menu does not display shortcuts and checkboxes. Therefore, it needs to modify the text displayed frequently to display its status. The code below shows how to set the specified text for the icon menu: menuitem. settitlecondensed ("short title"); iconsicon is the drawable resource ID, which is used to display in the menu item. Icons can only be displayed in the icon menu; they are not visible in the extended menu and sub-menu. The following code snippet shows how to apply the icon to the menu item: menuitem. seticon (R. drawable. menu_item_icon); the event processing function that will be executed when menu item click listener is selected. This approach is not recommended considering the efficiency factor. As an alternative, the menu item should be processed by the onoptionsitemselected processor, as shown later in this chapter. Apply a click listener to the menu item and use the style shown in the following code snippet: menuitem. setonmenuitemclicklistener (New onmenuitemclicklistener () {public Boolean onmenuitemclick (menuitem _ menuitem ){[... execute click handling, return true if handled...] return true ;}}); intents when a menu item is not processed by the menuitemclicklistener or onoptionsitemselected processing function of the activity, the intent specified to the menu item will be triggered. When triggered, Android will execute startactivity and pass in a specified intent. The following code snippet shows how to specify an intent for the menu item: menuitem. setintent (new intent (this, mytheractivity. Class ));
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.