I am working on an Android application. Somewhere inside, I am displaying the NumberPicker
widget.
How can I disable the transition between the minimum value and the maximum value?
What I mean, I am using a number picker, with a minimum value of 0 and a maximum value of 9999. It looks like this,
In this way, the user can quickly fling the widget to jump from 0 to 9999. I do not want this behavior. The number picker widget as it is now looks like a closed circle, and I am trying to see how I can break the circle exactly between the minimum and maximum value, so that it looks like this from the minimum value and maximum value:
How can I achieve this?
What I have tried :
NumberPicker
API, it doesn't seem like this is something that one can simply set using a method.setDisplayedValues(String[] displayedValues)
method to add empty strings before the minimum value and after the maximum value, so that no value is displayed before the minimum value or after the maximum value, BUT the user will still be able to fling past them or WORSE: select the empty value.Any ideas? Will I have to get my hands dirty and dig in the widget implementation? Inside the touch listener maybe?
You have to call setWrapSelectorWheel(false)
on the number picker. Be careful though that you do setMinimumValue(...)
and setMaximumValue(...)
before the call to setWrapSelectorWheel(false)
. It simply won't work if you do otherwise.
Like me, you may be looking for a way to do this via xml, but there is no way at the time.
Isn't this setWrapSelectorWheel(false)
(from the API)?
As pointed out, setWrapSelectorWheel(false) does the trick, so one of the offered answers should be accepted.
In general, this order of calls work:
picker.setMinValue(0);
picker.setMaxValue(stringValuesArray.length - 1);
picker.setDisplayedValues(stringValuesArray);
picker.setValue(defaultValue);
picker.setWrapSelectorWheel(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With