How can I programmatically display a ViewFlipper's second child?
Asked Answered
O

2

14

I have a ViewFlipper with 3 children.

I want to be able to display any of these children initially. So for example, maybe I want the ViewFlipper to load initially with the 2nd child and not the 1st.

EDIT: I know I can use the getChildAt(int index) method.

When a child in a ViewFlipper is shown, how can I get that child's index?

Otha answered 9/9, 2010 at 16:18 Comment(0)
S
22

I want to be able to display any of these children initially. So for example, maybe I want the ViewFlipper to load initially with the 2nd child and not the 1st.

Call setDisplayedChild().

When a child in a ViewFlipper is shown, how can I get that child's index?

Call getDisplayedChild().

Sagerman answered 9/9, 2010 at 16:57 Comment(1)
setDisplayedChild() does not work good with setInAnimation(). If animation is added, ViewFlipper does not hide other items than which is shown, all views are put on top of each otherHomerhomere
S
13

bringChildToFront(child) does nothing but changes the index value of the child.

In order to bring a child to the front without using showNext() or showprevious(),

use

setDisplayedChild() and indexOfChild() together.

example

vf.setDisplayedChild(vf.indexOfChild(child));

where child is the view that needs to be brought front.

Thanks

Suomi answered 13/7, 2011 at 9:50 Comment(1)
Great answer, here is how I did: vF.setDisplayedChild(vF.indexOfChild(findViewById(R.id.view)));Solidus

© 2022 - 2024 — McMap. All rights reserved.