I have a NumberPicker instance and it works as expected but I need to get value form it when scrolling stops Or when the user only press increments / decrements Button is pressed. the value that i should get it are displayed in the text view.
i managed to get the value when scrolling stops/ became idle and displayed correctly(this done in onScrollChanged()
listener).
but the onScrollChanged()
listener won't be fired when user press on increments or decrements buttons and if I use onValueChanged()
listener the text updated but scrolling became very laggy and slow( as result of updating all the time when value changed).
So I need help how to display the value of NumberPicker all the time without causing lagging or slowing of NumberPicker scrolling.
Code snipped as follow:
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);// array of numbers
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() + "");
//this is ok no lagging but will not work on pressing increments and decrements buttons
}
}
});
// If I use this
milisecNumberPicker.setOnValueChangedListener(new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
// set Text value here causing lagging on scrolling
}
});
Sorry bout bad formatting I'm new in this but can any one help me in this topic.
HI
...............