Tutorial step by step with free source code, pictures and video: how to set viewFlipper as live wallpaper on a button click in Android Studio version 1.5.1.

The idea of this project is to have two activities: in first the button, which on click will open the second activity where the slideshow with live wallpapers will start.

Create New Project with Application name: ViewFlipper on Button 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 and back.jpg (for background of your app).

Create New Java Class with Name: Slideshow and complete the code:

package com.example.toyo.viewflipperonbuttonclick;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ViewFlipper;
public class Slideshow extends Activity {
ViewFlipper viewFlipper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
viewFlipper = (ViewFlipper) this.findViewById(R.id.viewFlipper);
//sets auto flipping
viewFlipper.setAutoStart(true);
viewFlipper.setFlipInterval(3000);
viewFlipper.startFlipping();
}
}

ViewFlipper JavaClass source code

Create New XML layout file with Name: activity_second and complete the code by creating a ViewFlipper with 5 ImageView inside:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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>
</LinearLayout>

ViewFlipperActivity Second source code

In AndroidManifest. xml file add new activity you just created above (Slideshow):

<activity
android:name="Slideshow"
android:label="Second Activity">
</activity>

ViewFlipper AndroidManifest source code

Coplete code in activity_main.xml by setting the background and adding the Button:

<?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.viewflipperonbuttonclick.MainActivity"
android:background="@drawable/back">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="START SLIDESHOW"
android:id="@+id/button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"/>
</RelativeLayout>

ViewFlipperActivity Main source code

Complete the code in MainActivity.java:

package com.example.toyo.viewflipperonbuttonclick;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View v = findViewById(R.id.button);
v.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
if (arg0.getId() == R.id.button) {
//define a new Intent for the second Activity
Intent intent = new Intent(this, Slideshow.class);
//start the second Activity
this.startActivity(intent);
}
}
}

ViewFlipper Main Activity source codeThat’s all!
Run your app in Emulator and see the result: app in opening with a button on background picture and after your click, the slideshow with live wallpapers starts.

viewFlipper on button click source code

See video tutorial:

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

Check next tutorials to learn all about Android.
For further questions leave a message.

1 Comment

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

Can you please post a tutorial or a series of short videos on how to use google maps api in android studio that is getting last location, change location settings, receive location updates, set marker on map, creating geofence and gecoding?

Leave a Reply

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

Blue Captcha Image Refresh

*