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.
How to make NumberPicker non-recurring
Asked Answered
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.
It works like a charm. Exactly what I was looking for, thank you so much Opiatefuchs! –
Ecotone
You wouldn't happen to know the equivalent for a TimePicker by any chance? –
Ecotone
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. –
Overbite
see my edit...its not tested, but it could work in a similar way –
Overbite
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! –
Ecotone
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. –
Intransigent 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.
© 2022 - 2024 — McMap. All rights reserved.