Android Viewflipper Example

Here is a small and easy example of how to use viewflipper in android. Android viewflipper is used to add multiple views in a single Flipper.

ViewFlipperName.showNext() is used to show the next item in flipper. ViewFlipperName.showPrevious() is used to show the previous item in flipper.

Android ViewFlipper Example:
Xml file looks like

[sourcecode language="xml"]
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
<LinearLayout android:id="@+id/LinearLayout03"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:id="@+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Next"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Previous"></Button>

<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ViewFlipper android:id="@+id/ViewFlipper01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<!--adding views to ViewFlipper-->
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Flipper Content 1"></TextView>
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Flipper Content 2"></TextView>
<TextView android:id="@+id/TextView03" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Flipper Content 3"></TextView>


Java file looks like

[sourcecode language="java"]
public class ViewFlipperExample extends Activity implements OnClickListener {

Button next;
Button previous;
ViewFlipper vf;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
vf = (ViewFlipper) findViewById(;
next = (Button) findViewById(;
previous = (Button) findViewById(;


public void onClick(View v) {
// TODO Auto-generated method stub
if (v == next) {
if (v == previous) {

The output will looks like


Hi, Its possible. The code

Its possible. The code you have mentioned will work correctly.

Muniu, Its not possible to

Its not possible to view directly a particular View.
Try using while in this situation if you have more number of Views in ViewFlipper

Hi CB, See this post

Hi CB,
See this post

you can get some idea related to gesture handling.

@Tapan, You can't show or use


You can't show or use a layout more then one time.

@nicky let me assume that u

let me assume that u have mentioned "textview" as "view".
if that so
we can use 1 textview only once.we cant switch use it.

@Ali, Keep a static variable


Keep a static variable and store the value all time when view changed. Then restore it.