How to use Retrofit in Android Studio?

This is a simple tutorial on how to implement Retrofit, the REST api in your android application. If you are intending to save the REST data for offline usage, then How to use GreenDao in android studio? is a good read. Make sure you download the complete project.



PART 1: Setting up Retrofit REST Data.

In this tutorial, we are considering this json data.

You can host it here:

Inorder to format and validate the json, you can use :


PART 2 : Setting up Retrofit in Android Studio

  1. Add the dependency in your gradle.
  2. Add Internet Permission in the AndroidManifest.xml

  3. Now we need to create POJO (Plain Old Java Object  or Simple Normal Class ) for our JSON Data.
  4. Go Here:
  5. Add the json data and enter all the details
  6. Create a new Package in your Android Project and add the downloaded java files into the POJO folder (drag and drop).
    com.codekrypt.retroifit  >  New  > Package
  7. I bileave, you have something like this.2
  8. Create another class called to handle REST Interface.

PART 3: Setting Custom List View Adapter.

I have create a custom list adapter to handle extra fields. ( In case your application is listing more than one data in the list item. )

So let use see the code for custom List view adapter.


gradle dependencies.


PART 4: (Calling REST)

activity_main.xml  ( we have added listview )

That’s it .

When you launch the app, you will be able to see the company names, on the list view.

Reference :