Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block transition between minimum value and maximum value in NumberPicker

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,

number picker

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:

number picker minimum valuenumber picker maximum value

How can I achieve this?

What I have tried :

  • I searched everywhere in the NumberPicker API, it doesn't seem like this is something that one can simply set using a method.
  • I think that I can use the 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?

like image 712
Leeeeeeelo Avatar asked Mar 28 '13 14:03

Leeeeeeelo


3 Answers

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.

like image 128
doplumi Avatar answered Nov 17 '22 11:11

doplumi


Isn't this setWrapSelectorWheel(false) (from the API)?

like image 44
sgdesmet Avatar answered Nov 17 '22 12:11

sgdesmet


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);
like image 2
Disruption Avatar answered Nov 17 '22 11:11

Disruption