NumberPicker,当选择器停止滚动时拦截

时间:2017-12-22 14:57:51

标签: android numberpicker android-number-picker

我需要使用两个numberPicker,pickerOne和pickerTwo实现一个View。 pickerTwo值取决于pickerOne的当前值,因此当用户滚动pickerOne时,pickerTwo中的值会发生变化。我实现了pickerOne:

 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);
     }
 });

只有当用户逐步旋转(一次旋转一次)时,此代码才能正常工作,但如果用户执行“能量旋转”,则会在短时间内多次调用updatePickerTwoValues。 当选择器停止旋转时有一种方法可以拦截,所以只有当旋转停止时,我才能更新pickerTwo值?

0 个答案:

没有答案