The UnitPicker is a component that constructs a view for selecting quantities measured in certain units. It consists of a SwitchComponent that enables or disables the input mode, and a tumbler that is used for defining the quantity and the unit. There is an OK Command attached to the Toolbar that dismisses the UnitPicker.

Figure 1. A UnitPicker launched from a FormItem

The UnitPicker cannot be added to a Form as a Component. Instead, it needs to be launched from a component attached to a Form that can get a Listener, such as a Button, Command or FormItem. The developer provides a Vector containing a set of units as Strings. If the unit names are longer than 3 characters, they get truncated. There needs to be at least one unit defined, otherwise an IllegalArgumentException is thrown. The UnitPicker can be used for setting values from 0-999. A custom solution can be implemented using a UnitPickerContainer instance, if we need input of custom length.

The following snippet demonstrates the construction of a data limit picker, launched from a FormItem:

form = new Form("Unit picker Demo");

unit = new Vector();

picker = new UnitPicker("Data limit", "Limit", unit);
picker.setUnitPickerListener(new UnitPickerListener() {
    public void notifyUnitPickerListener(UnitPicker arg0) {

launcher = new FormItem("Set data limit", picker.getValue(), false);
launcher.setFormItemListener(new FormItemListener() {

    public void notifyFormItemListener(
        FormItem formItem,
        Component component,
    boolean actionButtonPressed) {

It is the developer’s responsibility to update the launcher’s value with the picker’s value once the UnitPicker is dismissed. The UnitPicker’s value is concatenated with the chosen unit and is returned as a String by the method getValue().

Last updated 29 July 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.