it displays One but I expect Two. I am confused. Why is One displayed
instead?
Because NumberPicker
works a little different from what you think.
In number picker you set the value with a code like this:
numberPicker.setMinValue(7);
numberPicker.setMaxValue(10);
Your NumberPicker
will have the numbers 7, 8, 9, 10.
Then use setDisplayedValues:
numberPicker.setDisplayedValues(new String[]{"One", "Two", "Three", "Four"});
The NumberPicker
has the strings "One", "Two", "Three", "Four".
Now change the min value :
numberPicker.setMinValue(10);
numberPicker.setMaxValue(10);
The NumberPicker
has the strings "One".
Why is that?
Because there is no correlation from real values and displayed values. As you can see in the source code of NumberPicker
this is how the displayed text is calculated:
String text = (mDisplayedValues == null) ? formatNumber(mValue) : mDisplayedValues[mValue - mMinValue];
So if your min value is 10 and the selected value is 10 the displayed text is the first element of the array.
Returning to your example if you want to display the string "Two" when set min and max value to 1 you need to change the array accordingly:
numberPicker.setDisplayedValues(new String[]{"Two"});
picker.setMinValue(1);
picker.setMaxValue(1);