1. Add the following code to the
createFields
method.// Create a numeric Choice showing values between 10 and 20 stepping by 2s NumericChoiceField numChoice = new NumericChoiceField( "Numeric Choice Field", 10,20,2); add(numChoice); // A separator field between each type of control add(new SeparatorField());
2. Add the following code to the
getData
method.if (f instanceof NumericChoiceField) { NumericChoiceField choice = (NumericChoiceField) f; int n = choice.getSelectedValue(); Dialog.alert("The selected value is " + Integer.toString(n)); }
3. As usual, debug the application and play with the new control that we added.
The differences between the NumericChoiceField
and the ObjectChoiceField
are minor, but using the right field for the right situation can make your job easier.
The first important point to notice is that the range and step values are supplied in the constructor. Actually, they must be supplied in the constructor...