Tutorial step by step with free source code: how to make a slideshow (display pictures one after another), with ViewFlipper starting only on your click on screen, in Android Studio version 1.5.1.

Create New Project with Application name: ViewFlipper on Click; Minimum SDK: API 10 – Android 2.3.3 (Gingerbread).
Add 5 pictures from your computer, in project folder app->res->drawable:  picture1.jpg,  picture2.jpg, picture3.jpg, picture4.jpg, picture5.jpg.

In app->res->layout->activity_main.xml add 5 ImageView inside of ViewFlipper and complete the code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.toyo.viewflipperonclick.MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ViewFlipper
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/viewFlipper">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:scaleType="centerCrop"
android:src="@drawable/picture1"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView2"
android:scaleType="centerCrop"
android:src="@drawable/picture2"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView3"
android:scaleType="centerCrop"
android:src="@drawable/picture3"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView4"
android:scaleType="centerCrop"
android:src="@drawable/picture4"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView5"
android:scaleType="centerCrop"
android:src="@drawable/picture5"/>
</ViewFlipper>
</LinearLayout>
</RelativeLayout>

In app->java->MainActivity complete the code:

package com.example.toyo.viewflipperonclick;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ViewFlipper;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
ViewFlipper viewFlipper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewFlipper = (ViewFlipper) this.findViewById(R.id.viewFlipper);
        viewFlipper.setOnClickListener(this);
}
    @Override
    public void onClick(View v) {
        viewFlipper.startFlipping();
        viewFlipper.setFlipInterval(3000);
    }
}

Tutorial ViewFlipper on Click in AndroidThat’s all!
Run your app in Emulator and see how the images begin to change after another, but only after you have clicked on the screen.

Watch the Video Tutorial:

Download free ViewFlipper.apk application from here and install it on your device to see how works.

For further questions leave a message.

3 Comments

You can follow any responses to this entry through the RSS 2.0 feed.

viewFlipper.setOnClickListener(this); nullpointer exception error help please

sorry this is not a flippview. plz send me flippview code to my email id

Hi, I need to rotate image in 180 degrees plz can some buddy help me in this ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image Refresh

*