|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.ui.Field
net.rim.device.api.ui.component.ChoiceField
net.rim.device.api.ui.component.NumericChoiceField
public class NumericChoiceField
A choice field that supports choosing from a range of numeric values.
Choice for a closed range of integers. This is intended to be used for
small ranges (for example, less than 20 items); otherwise, use
EditField
with a
NumericTextFilter
.
When creating a NumericChoiceField you specify a range of values that deviate by a single specified increment -- you cannot create a field with values unevenly spread across the range.
Behaviour
Looks like a ChoiceField.
Typing a digit will append it to the number. However, if nothing was previously typed (ie. the field is not muddy) then it will first be cleared. If the result is out of bounds, most significant digits will be taken off until the result is within the range or zero is reached in which case it will be set to the amount within the range closest to 0.
Space will add one, backspace will take away the last digit.
Field Summary |
---|
Fields inherited from class net.rim.device.api.ui.component.ChoiceField |
---|
CONTEXT_CHANGE_OPTION |
Constructor Summary | ||
---|---|---|
NumericChoiceField()
Constructs a new NumericChoiceField instance. |
||
NumericChoiceField(String label,
int begin,
int end,
int increment)
Constructs a new NumericChoiceField instance with label, range values and increment. |
||
NumericChoiceField(String label,
int begin,
int end,
int increment,
int initialIndex)
Constructs a new NumericChoiceField instance and sets initially selected value. |
Method Summary | ||
---|---|---|
Object |
getChoice(int index)
Retrieves value for specified index. |
|
int |
getPreferredWidth()
Retrieves this field's preferred width. |
|
int |
getSelectedValue()
Retrieves value of the currently selected choice. |
|
protected boolean |
keyChar(char key,
int status,
int time)
Traps key events to seek to the appropriate choice. |
|
protected boolean |
keyControl(char character,
int status,
int time)
Traps control key events to seek to the appropriate choice. |
|
protected boolean |
keyRepeat(int keycode,
int time)
Handles key repeat events. |
|
protected boolean |
keyStatus(int keycode,
int time)
Handles key status events. |
|
protected void |
makeContextMenu(ContextMenu contextMenu)
Builds this field's context menu. |
|
protected boolean |
navigationClick(int status,
int time)
Invoked when the navigational action is selected. |
|
protected void |
onUnfocus()
Invoked when this field loses focus. |
|
void |
setSelectedValue(int value)
Sets value of the desired choice. |
|
void |
setSelectedValue(int value,
int context)
Sets value of the desired choice. |
Methods inherited from class net.rim.device.api.ui.component.ChoiceField |
---|
drawFocus, getAccessibleContext, getFocusRect, getHeightOfChoices, getLabel, getPreferredHeight, getSelectedIndex, getSize, getWidthOfChoice, invokeAction, layout, moveFocus, paint, setEditable, setLabel, setNumberOfChoices, setSelectedIndex, setSelectedIndex, setSelectedIndex, setSize, toString, touchEvent, trackwheelClick, trackwheelUnclick |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public NumericChoiceField()
Builds a numeric choice field with no label, no starting or ending value, and an increment value of 1.
public NumericChoiceField(String label, int begin, int end, int increment)
label
- Label for this field.begin
- First value in the range.end
- Last value in the range.increment
- The amount to increase between each choice value.public NumericChoiceField(String label, int begin, int end, int increment, int initialIndex)
label
- Label for this field.begin
- First value in the range.end
- Last value in the range.increment
- The amount to increase between each choice value.initialIndex
- Index of the initially selected value.Method Detail |
---|
public int getPreferredWidth()
This field's manager invokes this method to assist in its layout.
getPreferredWidth
in class ChoiceField
public Object getChoice(int index)
getChoice
in class ChoiceField
index
- Index of choice for which to retrieve value.
public int getSelectedValue()
protected void makeContextMenu(ContextMenu contextMenu)
Be sure to save and terminate manual edit mode first.
Field.getContextMenu()
invokes this method to construct this field's
context menu.
If the UI is not operating in MODE_ADVANCED
mode (and
this field is Field.EDITABLE
), this method builds this field's context
menu adding a menu item for changing this field's value.
makeContextMenu
in class ChoiceField
contextMenu
- Context menu to build.ContextMenu
public void setSelectedValue(int value, int context)
value
- Value, not the index, of the desired choice (checked against
the maximum/minimum allowable values).context
- Context in which the change was made.public void setSelectedValue(int value)
value
- Value, not the index, of the desired choice (checked against
the maximum/minimum allowable values).protected boolean keyChar(char key, int status, int time)
This method handles and consumes a key generation event, only if this
field is Field.EDITABLE
; otherwise, it does nothing and does not
consume the event.
If the key generated was a number key, and the field has not already been changed (muddied), this method uses the number generated by the key press as the selected value. It then finds the nearest choice to this value from this field's list.
If the key generated was a number key, and the field has already been changed, this method concatenates the number generated by the key press to the selected value. It then finds the nearest choice to this value from this field's list.
If the key generated was a BACKSPACE character, this method divides the current selected value by 10 (i.e., deletes the last digit of the currently selected value). It then finds the nearest choice to this value from this field's list.
If the key generated was a DELETE character, this method sets the selected value to 0. It then finds the nearest choice to zero from this field's list.
If the key generated was a SPACE character, the behaviour is different depending on the style of the keyboard. On devices with a full QWERTY keyboard, this method first increments the selected value by one. It then finds the nearest choice to this value from this field's list. If incrementing puts the specified value beyond the end of the list, then this method wraps and selects the first choice in this field's list. However, on devices with a reduced QWERTY keyboard using a SureType® input method (like the BlackBerry Pearl 8100 Series smartphones), if the key generated was a SPACE character, this method multiplies the selected value by 10. It then finds the nearest choice to this value from the field's list.
keyChar
in class ChoiceField
key
- Character generated by the event.status
- State of the modifier keys.time
- Number of milliseconds since the device was turned on.
protected boolean keyRepeat(int keycode, int time)
By default, this method returns false; custom fields that specially handle key repeat events must override this method.
keyRepeat
in class Field
keycode
- Code of key repeated.time
- Number of milliseconds since the device was turned on.
protected boolean navigationClick(int status, int time)
The system invokes this method when passing on a navigational click event.
The ALT-click combination will enter selection mode, or if in selection mode will copy.
The source of the navigation event can be determined by checking the
KeypadListener.STATUS_TRACKWHEEL
and
KeypadListener.STATUS_FOUR_WAY
bits in the status
parameter; exactly one of them will be set.
navigationClick
in class Field
status
- Bitfield of values defined by KeypadListener
.time
- Number of milliseconds since the device was turned on.
protected void onUnfocus()
This method will not be invoked if this field does not already have the focus.
This method clears the muddy bit and removes selection, but it also ensures an edit-in-progress is saved and terminated.
onUnfocus
in class ChoiceField
protected boolean keyControl(char character, int status, int time)
NumericChoiceField.keyChar(char, int, int)
. Otherwise, it simply returns false.
keyControl
in class ChoiceField
character
- Character generated by the event.status
- Modifier key status.time
- Number of milliseconds since the device was turned on.
protected boolean keyStatus(int keycode, int time)
keyStatus
in class ChoiceField
keycode
- Code of status key.time
- Number of milliseconds since the device was turned on.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.