Android: set custom value to the NumberPicker
Thanks Mustanser for the pointer in the right direction. It's just important to note that setDisplayedValues takes a String array instead, so a functional answer would be:
NumberPicker picker = new NumberPicker(this);
picker.setMinValue(1);
picker.setMaxValue(3);
picker.setDisplayedValues( new String[] { "2", "5", "10" } );
Also, it is important to make sure you interpret the results of picker.getValue() correctly, since the underlying int values still run from 1 through 3:
int pick;
switch (picker.getValue()) {
case 1:
pick = 2;
break;
case 2:
pick = 5;
break;
case 3:
pick = 10;
break;
default:
//...
}
try some thing like this hope it will help you
NumberPicker picker = new NumberPicker(this);
picker.setMinValue(1);
picker.setMaxValue(3);
picker.setDisplayedValues( new int[] { 2, 5, 10 } );
Updated:
You can retrieve the selected number using code below
String value = picker.getDisplayedValues()[picker.getValue()];