Android NumberPicker OnValueChangeListener

I have a question regarding Android NumberPicker. When the user flings on NumberPicker, a Listener for is launched for each individual step OnValueChange. Can I change this so that oldVal and newVal can differ by more than 1 from each other, and Listener starts only once?

Thanks in advance.

EDIT: I will try to explain this more specifically in my code.

        int diff = Math.abs(newVal - oldVal);

        if (newVal - oldVal > 0) {
            sendMessage(te);
            for (int i = 0; i < diff; i++) {
                sendMessage(plus);
            }
            sendMessage(te);
        } else if (newVal - oldVal < 0) {
            sendMessage(te);
            for (int i = 0; i < diff; i++) {
                sendMessage(minus);
            }
            sendMessage(te);
        } else {
            if (D)
                Log.w(TAG, "This should NEVER happen");
        }

This method is called inonValueChange. It sends messages too fast for the connected device to respond on time. So I need to slow something down. Does anyone have an idea how to slow it down while not letting my main topic sleep? When he sleeps, the entire GUI does not respond during this time. I try to avoid this.

Thank.

+1
1

setOnValueChangedListener setOnScrollListener , SCROLL_STATE_IDLE. :

    numberPicker.setOnScrollListener(new NumberPicker.OnScrollListener() {

        private int oldValue;  //You need to init this value.

        @Override
        public void onScrollStateChange(NumberPicker numberPicker, int scrollState) {
            if (scrollState == NumberPicker.OnScrollListener.SCROLL_STATE_IDLE) {
                //We get the different between oldValue and the new value
                int valueDiff = numberPicker.getValue() - oldValue;

                //Update oldValue to the new value for the next scroll
                oldValue = numberPicker.getValue();

                //Do action with valueDiff
            }
        }
    });

, oldValue . ( ), , NumberPicker.OnScrollListener . - :

    public class MyNumberPickerScrollListener implements NumberPicker.OnScrollListener {

        private int oldValue;

        public MyNumberPickerScrollListener(int initialValue) {
            oldValue = initialValue;
        }

        @Override
        public void onScrollStateChange(NumberPicker numberPicker, int scrollState) {
            if (scrollState == NumberPicker.OnScrollListener.SCROLL_STATE_IDLE) {
                //We get the different between oldValue and the new value
                int valueDiff = numberPicker.getValue() - oldValue;

                //Update oldValue to the new value for the next scroll
                oldValue = numberPicker.getValue();

                //Do action with valueDiff
            }
        }
    }

. NumberPicker.onScrollListener.

+5

All Articles