This class provides a menu that is displayed when users press the Menu key. It consists of methods for populating the menu with objects (MenuItem objects, for example), and for customizing the appearance of the menu, (setFont(Font font), for example).
In the sample application, the menu is populated with MenuItem, SubMenu, and SeparatorField objects. Selecting the different options dynamically changes which objects are added to the menu, as well as how it looks.
This class creates submenus that are added to menus. The submenu is populated by MenuItem objects, that are added to the Menu object by invoking Menu.add(Submenu submenu).
In the sample application, the submenu is added to the menu object when you select the "Menu with sub menu" option. The submenu in the sample application is populated with DemoMenuItem objects, a subclass of MenuItem created in the sample application.
This class creates an object that represents an abstract menu item.
The sample application uses two subclasses of the MenuItem class, DemoMenuItem and ImageMenuItem. DemoMenuItem is created as an inner class, and demonstrates the SubMenu class by populating a SubMenu with DemoMenuItem objects. ImageMenuItem demonstrates how to add an image to menu items.
This interface allows a BlackBerry® device application to listen for changes to Field objects (for example, when a device user clicks a radio button) and respond to these changes. A class that implements this interface must implement fieldChanged(Field field, int context), which contains the code that manages the change. To specify a listener for a Field, you must invoke Field.setChangeListener(FieldChangeListener listener). You can specify a listener for any Field subclass, such as the Screen class or Manager class.
The sample application implements fieldChanged(Field field, int context) to listen for changes to three RadioButtonField objects. If the field selected is the "Menu with a custom border, background, and font" radio button, then the method sets the ObjectChoiceField object for the font menu to editable, allowing you to change the font used in the menu. Otherwise, the ObjectChoiceField is deactivated.
Files in the sample application
This file defines four classes, MenuDemo, MenuDemoScreen, DemoMenuItem, and ImageMenuItem.
The MenuDemo class extends UiApplication to support a user interface and contains the following constructor and methods:
The MenuDemoScreen class extends MainScreen to create the screen of the application, and implements the FieldChangeListener interface to listen for changes in the state of the fields on the screen. The MenuDemoScreen class contains the following constructor, methods and classes:
- MenuDemoScreen(): constructs a new MenuDemoScreen object, containing several types of fields, and adds these fields to the screen manager inherited from MainScreen, as well as three DemoMenuItem objects to populate the SubMenu
- fieldChanged(Field field, int context): implements fieldChanged(Field field, int context) of the FieldChangeListener interface. When a BlackBerry® device user selects the appropriate RadioButtonField object, the ObjectChoiceField object becomes editable
- makeMenu(Menu menu, int context): overrides MainScreen.MakeMenu(Menu menu, int context) to modify the default menu by adding menu items, sub menus, and images to menu items based on the fields that you select
- DemoMenuItem: an inner class with no executable code that extends MenuItem to demonstrate the Sub Menu API
- onSavePrompt(): a method from the MainScreen class overridden to return true, suppressing the save dialog before closing
The ImageMenuItem class extends MenuItem, and contains the following constructor: