Listener for ViewFlipper widget flipping events

Viewed 18997

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!

5 Answers

I know this question already has an answer. But here's an alternative which is a method ViewFlipper inherited from ViewGroup and which seems to be the best from my experience.

Code Snippets Below:

ViewFlipper viewFlipper = findViewById (R.id.myViewFlipperId);
viewFlipper.setOnHierarchyChangeListener(ViewGroup.OnHierarchyChangeListener);

The onChildViewAdded(View, View) method in the callback listener will be invoked whenever a child view is added to the ViewGroup. Which you can use to detect whenever the ViewFlipper flips.

See ViewGroup.html#setOnHierarchyChangeListener API Docs

Related