PowenKo, Android Tutorial 047-5, ScrollView, Viewflipper

September 3, 2011   ·   0 Comments

The output will looks like

reference: http://www.androidpeople.com/android-viewflipper-example

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

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<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>

<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>
</ViewFlipper>
</LinearLayout>

</LinearLayout>

Java file looks like

public class ViewFlipperExample extends Activity implements OnClickListener {

Button next;
Button previous;
ViewFlipper vf;

/** <a id="AdBriteInlineAd_Called" name="AdBriteInlineAd_Called" target="_top"></a>Called when the <a id="AdBriteInlineAd_activity" name="AdBriteInlineAd_activity" target="_top"></a>activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vf = (ViewFlipper) findViewById(R.id.ViewFlipper01);
next = (Button) findViewById(R.id.Button01);
previous = (Button) findViewById(R.id.Button02);
next.setOnClickListener(this);
previous.setOnClickListener(this);

}

@Override
public void onClick(View v) {
// <a id="AdBriteInlineAd_TODO" name="AdBriteInlineAd_TODO" target="_top"></a>TODO Auto-generated method stub
if (v == next) {
vf.showNext();
}
if (v == previous) {
vf.showPrevious();
}
}
}
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon