Someone Somewhere
Someone Somewhere

Reputation: 23787

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

I'm experimenting with this project: https://github.com/maarek/android-wheel/blob/master/wheel-demo/src/kankan/wheel/demo/extended/PasswActivity.java

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) {
    scroller.forceFinished(true);

    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() {
        @Override
        public void run() {
            //scroller.extendDuration(1000);
            scroller.setFinalY(finalYindex);
        }
    }, 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 ?

Upvotes: 0

Views: 237

Answers (1)

underoid
underoid

Reputation: 439

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.

Upvotes: 1

Related Questions