I wrote a small test program for flipperview. I have 3 views. I call startFlipping() to bring in the next view, so it goes from the first view, second, 3rd and back to the first
Is thee a way that instead of going to the next view, I could have flipper go directly to any of the 3 different views???
If not, is there a way to hide a vertical container? Maybe I could have 3 vertical containers, have 2 hidden and one shown?
code:
public class TestviewflipperActivity extends Activity implements
OnClickListener{
/** Called when the activity is first created. */
ViewFlipper mFlipper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// add listeners
View mButA = findViewById(R.id.flipbut);
mButA.setOnClickListener(this);
mFlipper = (ViewFlipper)findViewById(R.id.flipper);
View mBut = findViewById(R.id.back_btna);
mBut.setOnClickListener(this);
}
public void onClick(View v) {
mFlipper.startFlipping();
}
}
and the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button android:text="Go Back"
android:id="@+id/flipbut"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ViewFlipper android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/screenA"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST screen a"
android:layout_gravity="center"
android:padding="15dip"
android:textSize="22dip" />
<Button android:text="Go Back"
android:id="@+id/back_btna"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/screenB"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="screenb"
android:layout_gravity="center"
android:padding="15dip"
android:textSize="22dip" />
<Button android:text="Go Back"
android:id="@+id/back_btnb"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/screenC"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="screenC"
android:layout_gravity="center"
android:padding="15dip"
android:textSize="22dip" />
<Button android:text="Go Back"
android:id="@+id/back_btnc"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ViewFlipper>
</LinearLayout>
You should be able to use mFlipper.setDisplayedChild(int whichChild)
to make it filp to the view you desire in your code. The method is defined in ViewFlipper
's parent, ViewAnimator
.