I'm writing an application which has an interval time as a parameter and would like a field similar to the one the Timer has to set its time. Values of a few seconds to a few hours make sense for the application.
What type of field should I use?
I'm writing an application which has an interval time as a parameter and would like a field similar to the one the Timer has to set its time. Values of a few seconds to a few hours make sense for the application.
What type of field should I use?
Looks like a custom field.
Your choices with built-in fields are:
net.rim.device.api.ui.component.NumericChoiceField
, which basically acts like a drop-down with numbers in it (not great when you're talking about 60 minutes/seconds, but if you want to constrain to say 5 minute intervals or something it might be ok).
net.rim.device.api.ui.component.EditField
with a custom net.rim.device.api.ui.text.TextFilter
(you could use a NumericTextFilter
, but that wouldn't constrain you to 0-60, it'd allow any numbers).
Or you can roll you own. See this article for a start on creating custom fields. You'll probably want to override navigationMovement
to make the numbers increment/decrement on trackball up & down, and to move the focus within the field while going left & right - setting an internal state variable indicating where the focus is and overriding getFocusRect
to return an appropriate focus rectangle (be sure to call focusRemove
and focusAdd
from within navigationMovement
to let the framework know you've updated the focus).