0

My problem is that I want to go from layout 1 to any other layout by pressing a Button. For example:

From layout 1 with setDisplayChild(R.id.layout3) to go to layout 3 from a total of 4 layouts(Doesn't work).

I made a container.xml that includes all four layout, but I can't go for example from layout 2 to layout 4 directly without using flipper.showNext() or flipper.showPrevious() two times or things like this, the methods showNext() and showPrevious() are just to go forward or back and I need to go to any other layouts.

Is there a method for ViewFlipper to go from layout 1(or other layouts) to other layouts(that are not the neighbouring layouts) or the ViewFlipper knows just to go next, previous or the first layout(child)?

user
  • 86,916
  • 18
  • 197
  • 190

1 Answers1

1

Is there a method on viewFlipper to go from layout1 (or other layots) to other layouts(that are not the neighoubrs layouts) or the flipper knows just to go next,previous or the first layout(child) ?

Yes, there is the method setDisplayedChild from the ViewAnimator class which is the parent of ViewFlipper which allows you to move the ViewFlipper to whatever child you want.

For exemple: From layout1 with setDisplayChild(R.id.layout3) to go to layout 3 from a total of 4 layouts. (Doesen't work)

The setDisplayedChild requires that you pass to it the position of the desired View in the ViewFlipper element and not the id of that layout like you use it. So if you want to jump to one of the children of ViewFlipper just use:

viewFlipper.setDisplayedChild(2); // jumps to the third child
viewFlipper.setDisplayedChild(2); // another call like the one below will not move the ViewFlipper as it is already at the third child
viewFlipper.setDisplayedChild(1); // jumps to the second child

If you want to have the ViewFlipper move randomly through its children, then you could have:

Random mRandom = new Random();
viewFlipper.setDisplayedChild(mRandom.nextInt(4)); // 4 for 4 children
user
  • 86,916
  • 18
  • 197
  • 190
  • Thank you very much , i had waited a little for my respons but the solution that i got it's briliant! Thank you very very much! – Vlad-122112212 Jun 30 '12 at 21:00