Listener for ViewFlipper widget flipping events

前端 未结 5 1529
情话喂你
情话喂你 2020-12-09 09:12

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

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 09:33

    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

提交回复
热议问题