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:
protected void makeMenu(Menu menu, int instance) {
super.makeMenu(menu, instance);
for(int i = 0; i < menu.getSize(); i++) {
MenuItem menuItem = menu.getItem(i);
System.out.println("Name: " + menuItem.toString() + " Ordinal: " + menuItem.getOrdinal() + " Priority: " + menuItem.getPriority());
}
}
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!
protected void makeMenu(Menu menu, int instance) {
super.makeMenu(menu, instance);
for(int i = 0; i < menu.getSize(); i++) {
MenuItem menuItem = menu.getItem(i);
if (menuItem.getId() == 10089) { // ID for Switch Input Language
menu.deleteItem(i);
break;
}
}
}

Altering built-in menu items
Want to change the label for a built-in item? No problem:
protected void makeMenu(Menu menu, int instance) {
super.makeMenu(menu, instance);
for(int i = 0; i < menu.getSize(); i++) {
MenuItem menuItem = menu.getItem(i);
if (menuItem.getId() == 9) { // Close menu item
menuItem.setText("Adios"); // en espanol
break;
}
}
}

There is a setOrdinal method too, but this doesn’t seem to work - something I don’t understand about the menu implementation yet.
Anyway, this should get you started with playing with the BlackBerry system menus!






4 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
> There is a setOrdinal method too, but this doesn’t seem to work
You call super() every time in the first line, that renders the menu and uses getOrdinal(), if you change it after the super call, then it does not have effect.
Other: do anybody have a trick, how to add built-in “Enable SureType” or “Enable Multitap” items to a menu? It is so ugly to add an invisible field to the Manager just to have those menu items.
Thx for the tip, but, unfortunately I cannot get ti to work with getID(). All IDs are set to zero (!?)
Additionaly on 4.5 (tested on Pearl) you have to go in reverse direction (for(int i = menu.getSize()-1; i >=0 ; i–)) because the
menu.deleteItem(i);
shifts the menu items (while on 4.6 Bold it doesn’t)
Continuing the Discussion