How to make the android.widget.Scroller stop scrolling at a specific item index?


I'm experimenting with this project:

I've been trying to implement the following:

1) set the wheel to land on the number 5 (or any other number)

2) scroll the wheel for about 2 seconds

3) after spinning stops (could be any number of rotations through 0 to 9) the value shown is what's set in step 1

my work so far:

within WheelView -> WheelScroller I've added the following method (and also added a reference to the parent View):

public void flingToY(int initialVelocity, final int finalYindex) {

    lastScrollY = 0;
    final int maxY = 0x7FFFFFFF;
    final int minY = -maxY;
    scroller.fling(0, lastScrollY, 0, initialVelocity, 0, 0, minY, maxY);

    setNextMessage(MESSAGE_SCROLL);// specific to the view to allow it to scroll

    parentView.postDelayed(new Runnable() {
        public void run() {
    }, 1000);

the end result:

after the call to setFinalY() the wheel just stops turning and the digit that's shown is always "0"

You can see I experimented with extendDuration() which does extend the spinning, but in the end the result is the same; the spinning wheel suddenly stops and the digit "0" is shown on the wheel.

need help:

How can I get a "WheelView" to spin through the numbers 0 .. 9 for a second and then slow down to a predetermined position ?


1 Answer


public void setCurrentItem(int index, boolean animated) method of WheelView will smoothly scroll to given item and then stop if you pass true for animated value.

answered on Stack Overflow Feb 26, 2019 by underoid

User contributions licensed under CC BY-SA 3.0