androidviewflipper

Listener for ViewFlipper widget flipping events


I have a ViewFlipper implementation that needs to be improved. This ViewFlipper has three child views. Basically, I want an indicator on which child view is currently active. My ViewFlipper is just a part of a complex layout which also has list views, etc.

Switching of views is also automatic and done in a specified interval.

From Android's SDK reference, I haven't seen any listener for when the ViewFlipper changes the child view.

Do you guys know of a way I can have a listener for that event?

Or are there alternative ways I can implement this feature besides using ViewFlipper ?

Thanks!


Solution

  • If you apply animation (out or in animation) on view switching, you can set listener to an animation and, for example, act on animation end.

       viewFlipper.getInAnimation().setAnimationListener(new Animation.AnimationListener() {
          public void onAnimationStart(Animation animation) {}
          public void onAnimationRepeat(Animation animation) {}
          public void onAnimationEnd(Animation animation) {}
       });