Android AdapterViewFlipper Tutorial With Example

Hello Readers! In this post, we are going to learn about how to use android adapterViewFlipper widget in any android application. We will also go through different attributes of adapterViewFlipper widget that can be used to customise it.


Tutorialwing Android AdapterViewFlipper Output Android AdapterViewFlipper Tutorial With Example

Tutorialwing Android AdapterViewFlipper Output

Getting Started

AdapterViewFlipper widget can be defined as below –

AdapterViewFlipper is simple ViewAnimator that switches between views added to it. Only one child is shown at a time.

Attributes of Android AdapterViewFlipper Widget

Some of the popular attributes of android adapterViewFlipper widget are –

Sr. XML Attributes Description
1 android:autoStart If set true, it will automatically start animating views
2 android:flipInterval Duration after which current view will be replaced by next/previous view

Some of the popular attributes of android AdapterViewFlipper inherited from AdapterViewAnimator are –

Sr. XML Attributes Description
1 android:animateFirstView Defines whether to animate first view when viewAnimation is first displayed
2 android:inAnimation Defines the animation to use when view is shown
3 android:loopViews Defines whether to start from first view if the animator has at end of the list
4 android:outAnimation Defines the animation to use when view is hidden

Some of the popular attributes of android AdapterViewFlipper inherited from ViewGroup are –

Sr. XML Attributes Description
1 android:animateLayoutChanges Defines whether to run layoutTransition when there is any changes in layout
2 android:animationCache Defines whether layout animations should create a drawing cache for their children
3 android:clipToPadding Defines whether the ViewGroup will clip its children and resize (but not clip) any EdgeEffect to its padding, if padding is not zero
4 android:layoutAnimation Defines the layout animation to use the first time the ViewGroup is laid out
5 android:layoutMode Defines the layout mode of the viewGroup

Some of the popular attributes of android AdapterViewFlipper inherited from View are –

Sr. XML Attributes Description
1 android:alpha Defines alpha of the view
2 android:background Defines background of the view
3 android:backgroundTint Defines tint to apply to the background
4 android:backgroundTintMode Defines blending mode to apply to tint of the background
5 android:clickable Defines whether this view is clickable or not
6 android:elevation Defines z-depth of the view
7 android:focusable Defines whether this view can take focus or not
8 android:foreground Defines drawable to be shown above the view

Example of Android AdapterViewFlipper Widget

At first, we will create android application. Then, we will use adapterViewFlipper widget in this application.

1. Creating New Project

Follow steps below to create new project. Please ignore the steps if you have already created a new application.

Step Description
1. Open Android Studio.
2. Go to File => New => New Project. Write application name as AdapterViewFlipper. Then, click next button.
3. Select minimum SDK you need. However, we have selected 17 as minimum SDK. Then, click next button
4. Then, select Empty Activity => click next => click finish.
5. If you have followed above process correctly, you will get a newly created project successfully. However, you can also visit post to create a new project to know steps in detail.

Now, we will modify xml and java file to use adapterViewFlipper widget in the application.

2. Modify Values folder

Open res/values/strings.xml file. Then, add below code into it.

	<string name="app_name">AdapterViewFlipper</string>
	<string name="no_image">No Image</string>

3. Download Drawable Resources Needed

We need some drawable images for this tutorial. So, you can click here to download images to be used.

4. Create Animation for AdapterViewFlipper

We need animations to apply whenever there is switch between views. In this tutorial, we will define two animations left_in.xml and right_out.xml. left_in.xml will be used when view is shown. right_out.xml is used when view is hidden.

Follow steps below to define animations –
a. Create animator folder in main/res folder.
b. Now, create an xml file, left_in.xml, in main/res/animator folder. Then, add below code into main/res/animator/left_in.xml file.


c. Now, create an xml file, right_out.xml, in main/res/animator folder. Then, add below code into main/res/animator/right_out.xml file.


5. Create View For Single Item

Now, we will create view for single item in AdapterViewFlipper. So, create an xml file, item.xml, in res/layout folder. Then, add below code into it.

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




6. Create An Adapter For AdapterViewFlipper

Now, we will create an adapter for AdapterViewFlipper. This adapter provides data to the adapterViewFlipper to create different views. So, create a java file,, in main/java/com.tutorialwing.adapterviewflipper folder. Then, add below code into it.

package com.tutorialwing.adapterviewflipper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private String[] nameList;
	private int[] imageList;

	CustomAdapter(Context context, String[] nameList, int[] imageList) {
		this.nameList = nameList;
		this.imageList = imageList;
		inflater = LayoutInflater.from(context);

	public int getCount() {
		return (nameList != null) ? nameList.length : 0;

	public Object getItem(int position) {
		return null;

	public long getItemId(int position) {
		return 0;

	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = inflater.inflate(R.layout.item, null);
		TextView nameView = convertView.findViewById(;
		ImageView imageView = convertView.findViewById(;
		return convertView;

In Constructor, CustomerAdapter(…, …, …), we are providing context, nameList and imageList. getCount() method returns the number of views to be created. getItem() method returns the item at given index(i.e. position). getItemId() method returns id of the item at given position. getView() method is responsible to create views for given position in the adapter.

7. Use AdapterViewFlipper Widget in xml file

Open res/layout/activity_main.xml file. Then, add below code into it.

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



In activity_main.xml file, we have defined adapterViewFlipper. android:autoStart=”true” means adapterViewFlipper will automatically switch between different views. android:flipInterval=”3200″ means adapterViewFlipper will switch between different views at an regular interval of 3200 milliseconds. Now, we will access this adapterViewFlipper in java file to perform some operations on it.

8. Access AdapterViewFlipper Widget in java file

Open src/main/java/com.tutorialwing.adapterviewflipper/ file. Then, add below code into it.

package com.tutorialwing.adapterviewflipper;

import android.os.Bundle;
import android.widget.AdapterViewFlipper;

public class MainActivity extends AppCompatActivity {

	protected void onCreate(Bundle savedInstanceState) {

		AdapterViewFlipper adapterViewFlipper = findViewById(;
		if (adapterViewFlipper != null) {

			adapterViewFlipper.setInAnimation(getApplicationContext(), R.animator.left_in);
			adapterViewFlipper.setOutAnimation(getApplicationContext(), R.animator.right_out);

			String nameList[] = {"Guava", "JackFruit", "Mix Fruit", "Apple", "Pomegranate", "Strawberry", "Zespri Kiwi"};
			int imageList[] = {R.drawable.guava, R.drawable.jackfruit, R.drawable.mix_fruit,,
					R.drawable.pomegranate, R.drawable.strawberry, R.drawable.zespri_kiwi};

			CustomAdapter adapter = new CustomAdapter(this, nameList, imageList);

In file, we have accessed adapterViewFlipper defined in xml file. Then, we have set in and out animations that are used when view is shown/hidden respectively. Then, we have defined customAdapter and set it in AdapterViewFlipper.

Since AndroidManifest.xml file is very important in any android application, we are also going to see the content inside this file.


Code inside src/main/AndroidManifest.xml file is as below –

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.tutorialwing.adapterviewflipper"

		<activity android:name=".MainActivity">
				<action android:name="android.intent.action.MAIN"/>

				<category android:name="android.intent.category.LAUNCHER"/>


When we run the program, we will get output as shown above.

That’s end of tutorial on Android AdapterViewFlipper widget.

Leave a Reply