user940016 user940016 - 2 months ago 41
Android Question

Change the step size of a NumberPicker

Is it possible to do that in a more convenient way than handling it in the OnScrollListener event? Pity it doesn't have a step size attribute...

Answer

Why not just add an OnValueChangeListener Something like:

numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {

     @Override
     public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
         picker.setValue((newVal < oldVal)?oldVal-5:oldVal+5);
     }

});
Comments