Android AdapterViewFlipper Example using Retrofit and Glide

Hello guys in Android AdapterViewFlipper Example, we will learn using Android AdapterViewFlipper. We will use Retrofit to fetch data from a URL and we will also use Glide to load images from URLs. So lets begin …

android adapterviewflipper example

Hello guys in Android AdapterViewFlipper Example, we will learn using Android AdapterViewFlipper. We will use Retrofit to fetch data from a URL and we will also use Glide to load images from URLs. So lets begin with our Android AdapterViewFlipper tutorial.

What is Android AdapterViewFlipper?

AdapterViewFlipper is a UI element that can be used for switching views. We can create slider like things by using AdapterViewFlipper.

You can see a very simple example of android AdapterViewFlipper below.

Android AdapterViewFlipper Example

Our Web Service

  • I have a URL that is fetching me the data.

  • The above URL is returning the following data.

  • So we have name and imageurl. For fetching this data in android side we will use Retrofit and to load the image we will use Glide.

Creating a new Project

  • Create a new Project with an Empty Activity using Android Studio.
  • Now once the project is loaded add Retrofit, Gson and Glide to it.

Adding Dependencies

  • As we have to use Retrofit and Glide. Add the following lines inside your app level build.gradle.

  • Now sync your project with gradle.

Defining Retrofit Models

  • According to the JSON response we are getting we will need two models for Retrofit API.
  • First will store our hero. So create a class named hero.java and write the following code.

  • As the response contains a list of heroes, we need one more model class to store all the heroes in an ArrayList so create a class named Heroes.java and write the following code.

  • The models are ready now we will define the Retrofit service.

Creating Retrofit Service

  • Create an interface named APIService.java and write the following code.

  • The retrofit API is also ready. Now lets finally build our Android AdapterViewFlipper.

Creating AdapterViewFlipper

Creating Layout

  • Open activity_main.xml and add an AdapterViewFlipper .

Creating Layout for AdapterViewFlipper

  • We also need a layout for the screen of AdapterViewFlipper so create a file named flipper_items.xml inside layout directory and write the following xml code.

  • Now we will build the Adapter for our AdapterViewFlipper.

Creating Adapter

  • Create a class named FlipperAdapter.java and write the following code.

Fetching Data using Retrofit and Displaying it on AdapterViewFlipper

  • Now come to MainActivity.java and write the following code.

  • Now run your application and you will see your AdapterViewFlipper the same as you seen in the video demo.
  • If you are having problems building it you can try my source code. You can get my source code from below link.

[sociallocker id=1372]Android AdapterViewFlipper Example Source Code[/sociallocker]

So thats all for this Android AdapterViewFlipper Example. If you found it helpful please share it on your social networks. Also if you are having any confusions or queries lets discuss it on comments below. Thank You 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.

Expand Your Knowledge: Next Tutorial Picks

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x