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
.
Figure: EXCLUSIVE and MULTIPLE ChoiceGroups attached to a Form
Figure: POPUP and MULTIPLE ChoiceGroups appended to a Form
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(); } } }
ChoiceGroup
element has only one line of text
regardless of the fit policy.
When a POPUP ChoiceGroup
is opened, it is
displayed as an IMPLICIT
List
. Any Item
Command
s available
on the POPUP ChoiceGroup
are not carried over
into the opened ChoiceGroup
list. These Command
s are only available in the Form
.
If a Command
is added or removed after the Command
s for a displayable have been presented to the
user, all the Command
s are mapped again based
on the rules presented in the previous sections. This may update the
softkeys and Command
list items even when they
are visible.
For every ChoiceGroup
element type, pressing
the # key opens a separate screen displaying the selected choice
element’s text in its entirety.
If a MIDlet displays a ChoiceGroup
that has
no elements but has Item Commands
, the string empty
is displayed.
If the ChoiceGroup
has an image element and
if it is larger than the space allocated for it, it is cropped from
its right and bottom edges in order to fit within the space. If the
image element is smaller than the space allocated, it is centered
within the space provided.
When a MULTIPLE
or EXCLUSIVE
type ChoiceGroup
element is displayed on the
screen, pressing the Send key on the device causes the choice
element in focus to be selected if it was not selected before, or
is ignored if the element was already selected.
When a POPUP
type ChoiceGroup
element is displayed on the screen, pressing the Send key
on the device opens the ChoiceGroup
to display
all choice elements, in the style of an IMPLICIT
list.
Only plain, bold and italic font styles are supported in ChoiceGroup
s and List
s. Underlined
and combination styles are not supported.
ChoiceGroup
see: