Pages

Saturday, September 8, 2012

Android Flipper Example


Flipper class is used for simply flip the views.

package example.flip;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ViewFlipper;

public class FlipperEx extends Activity {
   Button b;
   ViewFlipper flip;
   LinearLayout ll;
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
       ll=(LinearLayout)findViewById(R.id.l_l);
       
        b=(Button)findViewById(R.id.button2);
        flip=(ViewFlipper)findViewById(R.id.viewFlipper1);

    }

    public void ClickHandler(View v)
    {

    flip.showNext();
     //flip.setFlipInterval(1000);
         // flip.setAutoStart(true);
   // flip.startFlipping();
    b.setGravity(Gravity.BOTTOM);
    ll.setGravity(Gravity.CENTER);
    }
    }

main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="top"
    android:id="@+id/l_l">
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

<EditText android:text="EditText"
android:layout_height="wrap_content"
android:id="@+id/editText1"
 android:layout_width="match_parent"
 android:gravity="right">
 </EditText>
<Button android:text="Button"
android:id="@+id/button2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:onClick="ClickHandler"
 android:gravity="top">
 </Button>
<ViewFlipper android:layout_width="match_parent"
 android:id="@+id/viewFlipper1"
  android:layout_height="wrap_content">

<TextView
android:text="first text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="second text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="third text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:text="fourth one is button"
android:id="@+id/button1"
 android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  </Button>


</ViewFlipper>
</LinearLayout>



No comments:

Post a Comment