Document 12643105

advertisement
 Another
class in the Form arsenal of Items is
ChoiceGroup.
 ChoiceGroup offers a list of choices , the user
can choose one or more of these options
according to the type of ChoiceGroup we will
detect it later
 The ChoiceGroup appears like any other
element in the Form; Figure 1 shows examples.
 The
constructor of this item is written on one of
these forms :
 ChoiceGroup(String label, int choiceType);
 ChoiceGroup(
String label , int choiceType ,
String[] stringElements , Image[] imageElements)
 Label : title will written above before options
written.
 choiceType : the type and it’s used by written name
of class ChoiceGroup , ( . ) and the type ( choose
one of these types) :
 EXCLUSIVE,
IMPLICIT, MULTIPLE
 EXCLUSIVE
: is a choice having exactly one
element selected at time. All elements of an
EXCLUSIVE type Choice should be displayed in-line.
That is, the user should not need to perform any extra
action to traverse among and select from the elements.

Value 1 is assigned to EXCLUSIVE.

POPUP : is a choice having exactly one element
selected at a time. The selected element is always
shown. The other elements should be hidden until the
user performs a particular action to show them. When
the user performs this action, all elements become
accessible. For example, an implementation could use
a popup menu to display the elements of a
ChoiceGroup of type POPUP.

The POPUP type is not valid for List objects.

Value 4 is assigned to POPUP.
IMPLICIT : static final int IMPLICIT is a choice in
which the currently focused element is selected when a
Command is initiated.
The IMPLICIT type is not valid for ChoiceGroup
objects, one element is always selected.
 Value 3 is assigned to IMPLICIT.
 MULTIPLE static final int MULTIPLE is a choice
that can have arbitrary number of elements selected at
a time.
 Value 2 is assigned to MULTIPLE.

 stringElements
: array of options that may add to
Choice Group
 imageElements : array of icons we like to add it
with the options , and the choice will appear with
icon image
If we don’t want any icon , the value of array will
be null
The selected state of a Choice object can be
controlled by the application with the
int getSelectedIndex()

Returns the index number of an element in the Choice
that is selected. For Choice types EXCLUSIVE, POPUP,
and IMPLICIT there is at most one element selected, so this
method is useful for determining the user's choice. Returns
-1 if the Choice has no elements (and therefore has no
selected elements).
 For MULTIPLE, this always returns -1 because no single
value can in general represent the state of such a Choice. To
get the complete state of a MULTIPLE Choice, see
getSelectedFlags.
 Returns: index of selected element, or -1 if none

int getSelectedFlags(boolean[] selectedArray_return)
 Queries the state of a Choice and returns the state of all
elements in the boolean array selectedArray_return.
Note: this is a result parameter. It must be at least as long as the
size of the Choice as returned by size(). If the array is longer, the
extra elements are set to false.

This call is valid for all types of Choices. For MULTIPLE,
any number of elements may be selected and set to true in the
result array. For EXCLUSIVE, POPUP, and IMPLICIT exactly
one element will be selected (unless there are zero elements in
the Choice).

Parameters: selectedArray_return - array to contain the
results

Returns: the number of selected elements in the Choice

void setSelectedIndex (int elementNum, boolean selected)
For MULTIPLE, this simply sets an individual element's
selected state. For EXCLUSIVE and POPUP, this can be
used only to select any element, that is, the selected
parameter must be true . When an element is selected, the
previously selected element is deselected. If selected is false ,
this call is ignored. If element was already selected, the call
has no effect.
 For IMPLICIT, this can be used only to select any element,
that is, the selected parameter must be true . When an element
is selected, the previously selected element is deselected. If
selected is false , this call is ignored. If element was already
selected, the call has no effect.

 The
call to setSelectedIndex does not cause
implicit activation of any Command.
 For all list types, the elementNum parameter
must be within the range [0..size()-1],
inclusive.
 Parameters :
 elementNum - the index of the element,
starting from zeroselected - the state of the
element, where true means selected and false
means not selected
void setSelectedFlags (boolean[] selectedArray) Attempts to
set the selected state of every element in the Choice. The array
must be at least as long as the size of the Choice. If the array
is longer, the additional values are ignored. For Choice
objects of type MULTIPLE, this sets the selected state of
every element in the Choice. An arbitrary number of elements
may be selected.
 For Choice objects of type EXCLUSIVE, POPUP, and
IMPLICIT, exactly one array element must have the value
true. If no element is true, the first element in the Choice will
be selected. If two or more elements are true, the
implementation will choose the first true element and select it.
 Parameters :selectedArray - an array in which the method
collect the selection status

 int
append (java.lang.String stringPart,
Image imagePart) Appends an element to the
Choice. The added element will be the last element
of the Choice. The size of the Choice grows by
one.
 Parameters : stringPart - the string part of the
element to be addedimagePart - the image part of
the element to be added, or null if there is no
image part
 Returns : the assigned index of the element
 void
delete (int elementNum) Deletes the element
referenced by elementNum. The size of the Choice
shrinks by one. It is legal to delete all elements
from a Choice. The elementNum parameter must
be within the range [0..size()-1], inclusive.
 Parameters : elementNum - the index of the
element to be deleted
 deleteAll
 void deleteAll(): Deletes all elements from this
Choice, leaving it with zero elements. This method
does nothing if the Choice is already empty.
 boolean
isSelected (int elementNum) Gets a
boolean value indicating whether this element is
selected. The elementNum parameter must be
within the range [0..size()-1], inclusive.
 Parameters
:elementNum - the index of the
element to be queried
 Returns :selection state of the element
 Example:
to create object choice from class ChoiceGroup :
ChoiceGroup choice = new ChoiceGroup("Choice
Title", Choice.EXCLUSIVE);
 To add options to ChoiceGroup :
choice.append("String1",null);
choice.append("String2",null);
choice.append("String3",null);
 To add the list of options( ChoiceGroup )to the
form:
frm.append(choice);
Download