×

ChoicePickerDemo

ChoicePickerDemo demonstrates how to use PopupChoicePicker and ContextMenu LWUIT Components.

Design

The MIDlet demonstrates the following components.

  • Single ChoicePicker: This shows how you can select a single option from a list of options available.

  • Multiple ChoicePicker: This shows how you can select a multiple options from a list of options available.

  • ContextMenu: This shows how you can add a Context Menu to your application. This demo uses a Show ContextMenu button that displays the various Context Menu options when clicked. The selected menu option is displayed below the Show ContextMenu button.

The MIDlet can be used in both portrait and landscape modes, and is tested on Nokia Asha SDK 1.0.

Implementation

Initialising LWUIT Display:

Display.init(this); // initialise LWUIT Display

Initialising the form:

Form myForm = new Form("ChoicePickerDemo");

Initialising single choice picker:

single = new PopupChoiceGroup("Single ChoicePicker", null, choices, PopupChoiceGroup.SINGLE);
myForm.addComponent(single);

Initialising multiple choice picker:

if (Display.getInstance().getDeviceType() == Display.ASHA_DEVICE) {
    multiple = new PopupChoiceGroup(" Multi ChoicePicker", info, options, PopupChoiceGroup.MULTIPLE);
    myForm.addComponent(multiple);
}

Initialising ContextMenu:

Label l = new Label("The button shows the context menu");
l.setFocusable(true);
l.setUIID("TitleLabel");
myForm.addComponent(l);

show = new Button("Show ContextMenu");
show.addActionListener(al);
myForm.addComponent(show);

Implementing Context Menu:

ActionListener al = new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
        if (evt.getSource() == show) {
            menuItemLabel.setText("");
            Command pressedMenuItem = null;
            Command[] cmd = new Command[6];
            cmd[0] = new Command("Menu item one");
            cmd[1] = new Command("Menu item two");
            cmd[2] = new Command("Menu item three");
            cmd[3] = new Command("Menu item four");
            cmd[4] = new Command("Menu item five");
            cmd[5] = new Command("Menu item six");
            pressedMenuItem = ContextMenu.show(cmd, show);

            if (pressedMenuItem != null) {
                menuItemLabel.setText(pressedMenuItem.getCommandName());
            }
        }
    }
};

Displaying the form:

myForm.show();

Last updated 24 June 2013

Back to top

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×