36

Is there any attribute to tell a (standard) NumberPicker to stop after its last value? E.g. if my MinValue was 0 and my MaxValue was 5 the NumberPicker just repeats itself after the 5, so that the user could scroll endlessly.

Simon Flückiger
  • 555
  • 1
  • 6
  • 11

2 Answers2

78

If You had set min/max value, try this:

yourNumberPicker.setWrapSelectorWheel(false);

does this work for you?

EDIT

For TimePicker:

timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
   public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
     if(hourOfDay>max) {
       TimePicker.setHour(max):
     }
     updateDisplay(hourOfDay, minute);
   }
});

It's not a tested code, but this could be the way you could do this.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49
  • It works like a charm. Exactly what I was looking for, thank you so much Opiatefuchs! – Simon Flückiger Nov 25 '12 at 19:56
  • You wouldn't happen to know the equivalent for a TimePicker by any chance? – Simon Flückiger Nov 25 '12 at 22:14
  • For TimePicker this is not possible in this way. There are different ways to do this. For Example, you could do Your own TimePicker. Or, an easier way, set the TimePicker to an OnTimeChangedListener and every time your max value is reached, use the setCurrentMinute/setCurrentHour method and set your min/max values. I try to give you an example later, but now I must hurry up to go to work. – Opiatefuchs Nov 26 '12 at 04:56
  • see my edit...its not tested, but it could work in a similar way – Opiatefuchs Nov 26 '12 at 15:06
  • Thanks Opiatefuchs, your code somewhat does what I asked for :-) I just hoped that there would be a nice and clean way of doing this as with the NumberPicker. Now the user can actually see that there are other Numbers available but they're just unreachable. I might have to look into custom pickers a little more to get this done. Thanks anyway! – Simon Flückiger Nov 26 '12 at 20:34
  • 4
    One thing to note about `NumberPicker.setWrapSelectorWheel(boolean)` - system decides whether to wrap or not wrap depending on the range of the values so this method should be called *after* setting the min/max values. – Czechnology Jun 04 '13 at 12:26
8

This Answer helped me:

public void updatePickerValues(String[] newValues){
  picker.setDisplayedValues(null);
  picker.setMinValue(0);
  picker.setMaxValue(newValues.length -1);
  picker.setWrapSelectorWheel(false);
  picker.setDisplayedValues(newValues);
}

Apparently the order matters.

Community
  • 1
  • 1
Zohar
  • 1,820
  • 1
  • 18
  • 16