I have an instance of NumberPicker and it works as expected, but I need to get its value when scrolling stops. Or when the user only clicks the "Increments / decrements" button. the value I should get is displayed in the text view.
I managed to get the value when the scroll stopped / became inactive and displayed correctly (this is done in the onScrollChanged()listener).
but the listener onScrollChanged()will not start when the user presses the increase or decrease buttons, and if I use the onValueChanged()listener, the text is updated, but the scrolling becomes very slow and slow (as a result of updating all the time when the value is changed).
So I need help how to display the NumberPicker value all the time without causing the NumberPicker to delay or slow down.
The code is disabled as follows:
NumberPicker milisecoundsNumberPicker = (NumberPicker) findViewById(R.id.numberPicker);
milisecNumberPicker.setFocusable(false);
milisecNumberPicker.setFocusableInTouchMode(false);
TextView textNumber = (TextView) findViewById(R.id.selectednum);
milisecNumberPicker.setMaxValue(10);
milisecNumberPicker.setMinValue(0);
milisecNumberPicker.setWrapSelectorWheel(false);
String[] nums = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
milisecNumberPicker.setDisplayedValues(nums);
milisecNumberPicker.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChange(NumberPicker view, int scrollState) {
if (scrollState == OnScrollListener.SCROLL_STATE_IDLE
|| scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
view.getValue();
textNumber.setText(view.getValue() + "");
}
}
});
milisecNumberPicker.setOnValueChangedListener(new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
}
});
Sorry for the poor formatting. I am new to this, but can anyone help me in this thread.
source
share