How to switch to a specific view using ViewFlipper?

I would like to switch to certain views in ViewFlipper. I currently have 6 children inside ViewFlipper. And I have buttons for navigation. It is very similar to the News and Weather app.

+44
android
Jul 04 '10 at 11:15
source share
2 answers

Call setDisplayedChild() , passing the index 0 child View that you want to display.

+87
Jul 04 '10 at 11:23
source share

See this simple example android.widget.ViewFlipper . With it, you can create various layouts from xml and then switch between them in a simple way:

  ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.myViewFlipper); // you can switch between next and previous layout and display it viewFlipper.showNext(); viewFlipper.showPrevious(); // or you can switch selecting the layout that you want to display viewFlipper.setDisplayedChild(1); viewFlipper.setDisplayedChild(viewFlipper.indexOfChild(findViewById(R.id.secondLayout) 

Xml example with tree layouts:

  <ViewFlipper android:id="@+id/myViewFlipper" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/firstLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > [...] </LinearLayout> <LinearLayout android:id="@+id/secondLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > [...] </LinearLayout> <LinearLayout android:id="@+id/thirdLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > [...] </LinearLayout> </ViewFlipper> 
+19
Jul 15 '13 at 7:33
source share



All Articles