Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make NumberPicker non-recurring

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.

like image 830
Simon Flückiger Avatar asked Nov 25 '12 17:11

Simon Flückiger


2 Answers

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.

like image 156
Opiatefuchs Avatar answered Nov 12 '22 16:11

Opiatefuchs


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.

like image 36
Zohar Avatar answered Nov 12 '22 16:11

Zohar