3

I need to implement a View with two numberPicker, pickerOne and pickerTwo. pickerTwo values depending on current value of pickerOne, so when user scroll pickerOne, values inside pickerTwo change. I've implement pickerOne like:

 NumberPicker pickerOne= new NumberPicker(context);

 pickerOne.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
 pickerOne.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); 
 pickerOne.setWrapSelectorWheel(false);
 pickerOne.setMinValue(0);
 pickerOne.setMaxValue(pickerOneValues.length-1);
 pickerOne.setDisplayedValues(pickerOneValues);
 pickerOne.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
     @Override
     public void onValueChange(NumberPicker numberPicker, int i, int i1) {
         Log.d("VALUE", "" + i1);
         updatePickerTwoValues(i1);
     }
 });

This code work well only if user do a step by step spin (one spin at time), but if user do an "energic spin" updatePickerTwoValues is called multiple time in a short time. There's a way to intercept when picker stop spinning, so only when spin stop, i can update pickerTwo values?

giozh
  • 9,868
  • 30
  • 102
  • 183
  • well, it does check the value changed, not whether or not the picker is moving. I think there's a separate listener for detecting "final" changes – Zoe Dec 22 '17 at 15:06
  • 3
    Please refer to [this](https://stackoverflow.com/questions/16591266/android-numberpicker-onvaluechangelistener) question. You can override the onScrollStateChange and check when the state is SCROLL_STATE_IDLE – dalla92 Dec 22 '17 at 15:08
  • Did you find a solution to this? – jlively May 14 '18 at 10:50
  • @dalla92 Thanks for sharing the information – Maulik Dodia Aug 08 '19 at 07:15

0 Answers0