I have a ViewFlipper set to auto-flip every 5 seconds. Leaving out some of the details, it looks like this and works fine:
ViewFlipper flipper = (ViewFlipper) findViewById(R.id.myflipperid);
flipper.setFlipInterval(5000);
flipper.setInAnimation(inFromRightAnimation());
flipper.setOutAnimation(outToLeftAnimation());
flipper.startFlipping();
However, I have a case where I want the auto-flipping to stop at the last view, rather than looping around to start over again. It doesn't seem that ViewFlipper or any of the classes it inherits from have a looping control method.
How can I get ViewFlipper to stop looping through its child views when it hits the last one?
Note: the answer given here doesn't apply to my case, as I need to catch the ViewFlipper at the end of its list, i.e., without depending on user input. Thanks.
Here's the solution I used. As suggested here, the trick is to listen for the end of animation event, and then check to see if the flipper is on the last view.
flipper.getInAnimation().setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
int displayedChild = flipper.getDisplayedChild();
int childCount = flipper.getChildCount();
if (displayedChild == childCount - 1) {
flipper.stopFlipping();
}
}
});
Thanks for your answers.
I haven't tried this my self but I hope this will help.
First, Try to listen to your viewflipper's flip events. Since you are using an animation. You may use the solution posted here: https://stackoverflow.com/a/3813179/1594522
Then, onAnimationEnd(), you can check if the viewflipper is on its last child view. If it is already on its last child view, then call flipper.stopFlipping().
Hope that helps! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With