I’d like to display the amount a number picker value changed from when a user starts scrolling to the final value. I’ve found the OnValueChangeListener but the problem is this gets called on every number scrolled past whereas I’d like the total change in value. I looked at the OnScrollListener but that doesn’t seem to do what I’d like either.
Is there an event that fires when a user first starts scrolling? And likewise an event when a numberpicker stops spinning?
It seems like it should be very easy to achieve but I’m struggling. For example NumberPicker starts at initial value of 20 user scrolls to 11 so amount changed is 9.
The answer is really quite simple… just store the initial and final values and take the difference between the two.
Before you inflate/instantiate the
NumberPicker, note its initial starting value. For example, create a private instance variableprivate int mInitialValue. Then when you give yourNumberPickerthe initial value to 20,When the user exits the activity (or whenever you determine that a “final” value has been set), store its value (i.e.
mFinalValue). Then take the difference withmFinalValue - mInitialValue.