Creating a pop-up menu

You can create a pop-up menu by using classes that are available in the net.rim.device.api.ui.menu package, and you can define the functionality of the pop-up menu items by using the Command Framework API.

A pop-up menu consists of a context menu provider, a command item provider, and command items.

Component

Description

Context menu provider

You use the DefaultContextMenuProvider class to create and display a screen's pop-up menu. When a BlackBerry® device user opens a pop-up menu, the context menu provider looks for fields on the screen that are command item providers. DefaultContextMenuProvider is the default implementation of ContextMenuProvider. If you do not provide a screen with a context menu provider, the legacy context menu is converted and displayed as a pop-up menu.

Command item provider

You use the CommandItemProvider class to configure a field on your UI screen so that the field can provide context and command items to the pop-up menu based on the current context. For example, you could configure an email address as a command item provider and provide the user with different actions based on whether the email address is in the user's contact list.

Command items

You use the CommandItem class to specify the text, icon, and behavior of a pop-up menu item. You define the behavior of the pop-up menu by using a command. The command acts as a proxy to an instance of a command handler, which defines the functionality of the pop-up menu item. For example, for an email address, you could provide command items to add or view a contact based on whether the selected email address appears in the user's contact list. The command handler would contain the code to add or view the contact.

For more information on commands and command handlers, see Command Framework API. The Command Framework sample application that is provided in the BlackBerry® Java® SDK demonstrates commands and command handlers.

If you use a legacy context menu, BlackBerry® Device Software 6.0 converts the context menu items to command items and provides them to the command item provider. For more information, see Support for legacy context menus.


Was this information helpful? Send us your comments.