Private void addRegular MenuItems Menu menu

int base=Menu.FIRST; // value is 1

menu.add(base,base,base,"append"); menu.add(base,base+1,base+1,"item 2"); menu.add(base,base+2,base+2,"clear");

menu.add(base,base+3,base+3,"hide secondary"); menu.add(base,base+4,base+4,"show secondary");

menu.add(base,base+5,base+5,"enable secondary"); menu.add(base,base+6,base+6,"disable secondary");

menu.add(base,base+7,base+7,"check secondary"); menu.add(base,base+8,base+8,"uncheck secondary");

chapter 5 ■ working with menus and dialogs

The Menu class defines a few convenience constants, one of which is Menu.FIRST. You can use this as a baseline number for menu IDs and other menu-related sequential numbers. Notice how you can peg the group ID at base and increment only the sort-order ID and menu-item ID. In addition, the code adds a few specific menu items such as "hide secondary," "enable secondary," and others to demonstrate some of the menu concepts.

0 0

Post a comment