ChoiceGroup

ChoiceGroup is a group of selectable elements which may be created with a mode that requires a single choice to be made or that allows multiple choices. ChoiceGroup is in many ways similar to List and they both implement the same Choice interface.

The differences between ChoiceGroup and List are that the IMPLICIT type is not in use in ChoiceGroup and the POPUP type is used only in ChoiceGroup.

Note: Since ChoiceGroup is also an Item, the general properties of the Form Items are applied. In particular it means that ChoiceGroup has two focus indicators: One for the highlighted element inside the ChoiceGroup and one for ChoiceGroup itself inside the Form.

Figure 23: Two example ChoiceGroups. Notice the label change in Selection key.

Source code for the example:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ExampleForm4 extends MIDlet implements CommandListener {
    private Form form;
    private Command exit;
    
    public ExampleForm4() {
        form = new Form("Form example 4");
        //ChoiceGroup(label,type,elements,image)
        ChoiceGroup Choice1 = new ChoiceGroup ("Exclusive choice", Choice.EXCLUSIVE,new String[] {"Choice 1", "Choice 2", "Choice 3"}, null);
        ChoiceGroup Choice2 = new ChoiceGroup ("Multiple choice", Choice.MULTIPLE,new String[] {"Choice 1", "Choice 2", "Choice 3"}, null);
        form.append(Choice1);
        form.append(Choice2);
        exit = new Command("Exit", Command.EXIT, 1);
        form.addCommand(exit);
    }      
    public void startApp() {
        Display display = Display.getDisplay(this);
        display.setCurrent(form);
    }
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command command, Displayable displayable) {
        if (command == exit) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
}

For more information about S60-specific ChoiceGroup features, see ChoiceGroup implementation notes.