A ChoiceGroup allows a single choice to make or mulitple choices. There are 3 different types of choice Explicit,Implicit and Pop-up.

Illustration below displays different ChoiceGroups.

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

public class ChoiceMidlet extends MIDlet implements CommandListener {
    
    Command exit = new Command("Exit", Command.EXIT, 1);
    private Display display;
    private boolean firsttime;
    private Form form;
    
    public ChoiceMidlet() {}
    
    protected void startApp() {
        display = Display.getDisplay(this);
        form = new Form("Choice Midlet");
        
        String[] stringArray = {"Choice A", "Choice B", "Choice C"};
        
        ChoiceGroup[] groups = {
            new ChoiceGroup("Exclusive", 
                    ChoiceGroup.EXCLUSIVE, stringArray,null),
            new ChoiceGroup("Multiple", 
                    ChoiceGroup.MULTIPLE, stringArray,null),
            new ChoiceGroup("Pop-Up", 
                    ChoiceGroup.POPUP, stringArray,null)
        };
        for (int i = 0; i < groups.length; i++) {
            form.append(groups[i]);
        }
        form.addCommand(exit);
        form.setCommandListener(this);
        display.setCurrent(form);
    }
    
    public void commandAction(Command c, Displayable d) {
        if (c == exit) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
    
    protected void destroyApp(boolean unconditional) {}
    
    protected void pauseApp() {}
}

 

 

 

 Related Tips