Creating the Domain Field and Check Box
The Domain field should be a drop-down list. For the BlackBerry, this is accomplished by an instance of net.rim.device.api.ui.component.ChoiceField. You can implement the interface directly, but for this application, the net.rim.device.api.ui.component. ObjectChoiceField component will do just fine; it allows us to specify an array of Objects, which will be used to populate the field (the toString method will be used for the display string). If you want a list of numbers, net.rim.device.api.ui.component. NumericChoiceField is also often useful.
We'll add the imports for both of these fields first:
import net.rim.device.api.ui.component.CheckboxField; import net.rim.device.api.ui.component.ObjectChoiceField;
Then, we add the declaration of the member variables, again at the top of the
UiFunMainScreen class:
ObjectChoiceField domainField; CheckboxField rememberCheckbox;
Because we're just using hard-coded values for this application, instantiating our ObjectChoiceField is easy:
domainField = new ObjectChoiceField("Domain:", new String[] {"Home", "Work"}); add(domainField);
And by this point, you can probably figure out how to use net.rim.device.api.ui.component.CheckboxField to create a check box on screen; there's nothing special to note about CheckboxField except that you have to specify the state of the check box (true for checked or false for unchecked) when you instantiate it:
rememberCheckbox = new CheckboxField("Remember password", false); add(rememberCheckbox);
Post a comment