ShawnLin013 / NumberPicker

:slot_machine: The android library that provides a simple and customizable NumberPicker.
MIT License
1.07k stars 240 forks source link

The wheel keeps on scrolling #191

Open varunchandran333 opened 3 years ago

varunchandran333 commented 3 years ago

https://user-images.githubusercontent.com/24404413/108030469-4d849e00-7055-11eb-9cf5-fd664c6437f9.mp4

The number is reset on unchecking the checkbox. Then some time this happens on reset. What is the best way to reset the number picker?

thirstycoda commented 3 years ago

I'm using this control with np_wrapSelectorWheel set to false so I didn't see the same behaviour as you, but I saw a problem which may have the same cause. My problem sometimes occurred when using setValue. Thought I'd post my workaround in case it helps.

So it looks like in the computeScroll() function, it's possible for line 1236 scrollBy(currentScrollerX - mPreviousScrollerX, 0); to be called with the result of currentScollerX - mPreviousScrollerX being something similar to the minimum value of int (-2147483648). This results in the code entering while (mCurrentScrollOffset - mInitialScrollOffset < -gap) { at line 1333 and continue to loop around for a very long time.

I don't know much about the library but I get the impression that the problem may related to mPreviousScrollerX not being reset correctly.

My workaround was to call smoothScroll(false, 0) immediately after using setValue. I used smoothScroll because there is a line in there that sets mPreviousScrollerX to 0.

varunchandran333 commented 3 years ago

same issue exist after smoothscroll