How to use AdapterViewFlipper

Updated 18 August 2017

Save

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

author
. . .

Leave a Comment

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


3 comments

  • Moses Katsina
    • Vedesh Kumar (Moderator)
  • Abhishek
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home