Skip to content


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:

	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

Menu Below Close

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;
			}
		}
        }

Menu Switch Input Language gone

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;
			}
		}
	}

Close Adios

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!

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google

Posted in advanced, eclipse, hacks, ui. Tagged with , , , , .

4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Jamesgt said

    > 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.

  2. Myraddin said

    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

  1. Developing Blackberry application « Lubos Programming Weblog linked to this post on January 12, 2010

    [...] BlackBerry menu ordinals and priorities – Part 2: System menu items [...]

  2. Planet Android » Blog Archive » Some Useful BlackBerry development tutorials and Custom UI components linked to this post on April 17, 2010

    [...] Issues: http://www.thinkingblackberry.com/archives/144 UI Threading and issues BB MenuItems: Menuitems ordinals and priorities Storing data in persistent Storage: BB OS 5.0 recently introduced SQLite. Previous OS only [...]

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.