Android Retrofit Http Library Fetch Json ListView Tutorial Example

By | July 20, 2019
Android Retrofit Http Library Tutorial Example

What is Retrofit Http Library in Android ?

Retrofit is type-safe REST client for Android and Java which aims to make it easier to consume RESTful web services.

Retrofit is not to the details of Retrofit 1.x versions but It is Jump into Retrofit 2 Version directly which has a lot of new features and a changed internal API compared to the previous versions.

Retrofit 2 is a by default OKHttp  networking layer and is built on top of it.

Retrofit is a automatically serialises the JSON response using a POJO(Plain Old Java Object) we must be defined in advanced for the JSON Structure.

Serialized JSON we need a convert to Gson.And then Access And Retrieve Data from Retrofit to Your App.

What is Gson in Android ?

Gson is a java library that converts Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. 

How to Fetch Retrofit ListView Data in Android ?

In this Tutorial Using Retrofit Fetch the Data from url to ListView. It is fetch Images And Texts From URL. And Then Set the Adapter of ListView and Display the List of Item in Retrofit.

I have Create an Object of Retrofit and then Create Interface. Interface is used to Send and Receive Data from URL. In this Interface Method Called on your Activity or Fragment and then Pass the POJO Class to get And Set Data into your Retrofit to URL.

Example Of Retrofit with ListView in Android

Declared Permission in AndroidManifest.xml File.

Add Dependency in App Level build.gradle File.

Create activity_main.xml File Follow this Code.

Create item_list.xml File Layout Follow this Code.

Create Class Follow this Code.

Create Class To POJO Class.

Create Interface in File Follow this Code.

Create File Follow this Code.

Create Follow this Code.

Android Retrofit ListView JSON Parshing Tutorial Example

Above the Code To Create Simple ListView and then Create RetrofitData Class to Object of Retrofit and then Put the URL from Get the Data and and then Set The ListView Adapter Data and Display Data.

In this Tutorial used to Glide Library to Download Image from Server and then set the Image in ImageView. In this Tutorial Create Custom ListView Adapter and then set the custom Layout File to Declared ImageView and then Fetch Data from URL To Bind this Layout Adapter and then Set The Data from Layout View.