BlackBerry menu ordinals and priorities – Part 2: System menu items

Part 1 explained basically how BlackBerry menus are ordered. In part 2 we’ll look at where system menu items (such as Close, Copy and Paste) fit, and how to work with them.

The interesting stuff

Built-in menu items

Built in menu items all have priorities and ordinals too. We can use the following bit of code (with the right kinds of controls on screen) to get the values:

view plaincopy to clipboardprint?
  1. protected void makeMenu(Menu menu, int instance) {
  2.     super.makeMenu(menu, instance);
  3.     for(int i = 0; i < menu.getSize(); i++) {
  4.         MenuItem menuItem = menu.getItem(i);
  5.         System.out.println(“Name: “ + menuItem.toString() + ” Ordinal: “ + menuItem.getOrdinal() + ” Priority: “ + menuItem.getPriority());
  6.     }
  7.        }

So we get the following values:

Menu Item Ordinal Priority Id
Select 196720 500 7
Copy 196672 200 3
Cut 196688 300 4
Cancel Selection 196736 350 10
Paste 196704 400 6
Clear Field 219392 2147483647 2
Show Symbols 50680656 2147483647 10065
Enable Multitap 50680656 2147483647 0
Switch Input Language 50680656 2147483647 10089
Close 268501008 1073741823 9

So the priorities for some of the items (Clear Field, Show Symbols, Enable Multitap, and Switch Input Language) are Integer.MAX_INT, so they’ll always be the lowest priority. Other than that, there’s plenty of room in between all of those numbers to put other menu items wherever you want.

Say you wanted something to appear below the Close menu item. Just create a menu item like:

new MenuItem("Below Close", 300000000, 100) ... // etc

 

Also notice the Id value – this is obtained from MenuItem.getId() and won’t change, even if the device language changes the label of the item. These do not correspond to the constants in MenuItem (MenuItem.CLOSE, etc) – though some aren’t represented there.
The value comes in handy for these next tricks.

Removing built-in menu items

Always hated that Switch Input Language menu item? Here’s how to get rid of it!

view plaincopy to clipboardprint?
  1. protected void makeMenu(Menu menu, int instance) {
  2.     super.makeMenu(menu, instance);
  3.     for(int i = 0; i < menu.getSize(); i++) {
  4.         MenuItem menuItem = menu.getItem(i);
  5.         if (menuItem.getId() == 10089) { // ID for Switch Input Language
  6.             menu.deleteItem(i);
  7.             break;
  8.         }
  9.     }
  10.        }

Leave a Reply

Your email address will not be published. Required fields are marked *