Start a Project

How to use AdapterViewFlipper

A regular ViewFlipper shows only one child widget or container at a time. So does an AdapterViewFlipper. The difference is where the children come from. With a regular ViewFlipper, you add children much like you would any other standard container class, such as defining the children in your layout XML resource. With AdapterViewFlipper, the children come from an Adapter.

AdapterViewFlipper is actually a view animator. It can animate a number of views that have been added to it. It has functions like showNext() or showPrevious() which are used to flip between two views. It can also do the automatic flipping by startFlipping().

Let us Discuss you to implement AdapterViewFlipper in your Android App.

First, You need to declare an AdatperViewFlipper in your layout file. Look at the code below for example.

 

Now, We will create a layout of the item which will be used in the flipper. Suppose we have created a layout your_view_item.xml with an ImageView and a TextView.

 

Now, When the item layout is ready we will create an Adapter for our AdapterViewFlipper which will add the views in it. This adapter will extend BaseAdpter class.

 

Now, We have everything set. Let’s connect them all to create a working AdapterViewFlipper.

As we have taken an ImageView and TextView, We need the data which will be filled in them. Let us take some dummy data. An array of int for images and an array of String for names.

After this where you need to initialize the AdapterViewFlipper just create an instance of YourFlipperAdapter and set the adapter to AdapterViewFlipper.

That’s all, Your AdapterViewFlipper will automatically switch between the views with an animation.

Thank you very much. This is Vedesh Kumar signing off.

Sources : https://developer.android.com/reference/android/widget/AdapterViewFlipper.html

Exit mobile version