是否有可能改变NumberPicker时长pressing增量? [英] Is it possible to change the increment of NumberPicker when long pressing?

查看:175
本文介绍了是否有可能改变NumberPicker时长pressing增量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3900号,用户使用 NumberPicker 来选择一个单一的数量从范围。现在,当长pressing了在选择器/下箭头,这个数字增加/缓慢下降。我已经坐在 setOnLong pressUpdateInterval() 0毫秒,但它仍然在这个大范围内的数字增加缓慢。

I have range of 3900 numbers which the user use the NumberPicker to pick one single number from. Now, when long pressing up/down arrows in the picker, the numbers are increased/decreased slowly. I have sat the setOnLongPressUpdateInterval() to 0 milliseconds, but it still increment slowly in this large range of numbers.

是否有可能改变的增量在选择器时的长pressing 向上/向下箭头,因此增加数由可以说100,并释放时,转向回递增1按钮?

Is it possible to change the increment in the picker when long pressing the up/down arrows so it increases numbers by lets say 100, and turns back to increment of 1 when releasing the buttons?

推荐答案

我把这个方法,因为工作套住长preSS似乎令人担忧。

I took this approach, since the work to trap the long press seemed worrisome.

NumberPicker _picker;
long _tsLastChange;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.number_picker);

    _picker = (NumberPicker) findViewById(R.id.picker);
    _picker.setMinValue(1);
    _picker.setMaxValue(3900);
    _picker.setOnLongPressUpdateInterval(100);

    _picker.setOnValueChangedListener(new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            Log.d("NumberPickerActivity", "value changed detected");
            long tsChange = System.currentTimeMillis();
            if (tsChange - _tsLastChange < 200)
            {
                if (newVal > oldVal)
                    _picker.setValue(newVal + 100);
                else 
                    _picker.setValue(newVal - 100);
            }
            _tsLastChange = tsChange;
        }
    });
}

要得到这个工作IRL,你可能会想(一)轮的newval到最近的100什么的,和(b)担心概括情况比我还多。

To get this to work IRL, you would probably want to (a) round "newVal" to the nearest 100 or something, and (b) worry about wraparound cases more than I do.

有点令我感到诧异的是,纲领性的setValue 似乎并没有引起无限递归的 onValueChangedListener

Somewhat surprising to me is that the programmatic setValue does not seem to cause infinite recursion in onValueChangedListener.

我使用Theme.Black的主题,以获得该测试在4.1模拟器的老土 NumberPicker 与+/-按钮。

I tested this on a 4.1 emulator using the "Theme.Black" theme, to get the "old fashioned" NumberPicker with +/- buttons.

这篇关于是否有可能改变NumberPicker时长pressing增量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆