Fetching data from server is a most common functionality almost in every app, and for which there are several parameters like time taken for fetching data or uploading, connectivity, speed, security and many more so today we will be looking over a library which will help you fetch data from your api’s much more faster.

Retrofit Library works with your HTTP API in making it into a java interface making it much flexible and faster for you, which also helps in over all performance of the app.

In this tutorial on Retrofit library we can fetch data from an api and show it in a android recyclerview.

Add Retrofit, recyclerview, gson to your project

 

 

Lets design the row of the listview

listview_row

Add two textviews to the layout for displaying username and age.

 

and then

 

activity_main

 

then create a api interface

 

ApiInterface

In post declare your parameter.

ApiClient

Declare your base url here.

 

Pojo class for handling data in between api and adapter.

 

Contact

 

RecyclerAdapter

 

MainActivity

Now we can fetch data using our apiinterface

 

 

 

 

Manifest

Declare internet permission

Output

 

Show Buttons
Hide Buttons
Read previous post:
Android Fresco Image Library || Load Images Using Fresco

Close