0

Hi is there any simple way to use retrofit with recyclerview to fetch json parser from my online website . So far i used Okhttp to get data from local server.A detailed answered will be really appreciated.Thanks in advance.

Pathtaker
  • 5
  • 3
  • What is simple way according to you ? What you have tried so far ? Retrofit is already simple to use. Please explain your query where exactly you are facing a problem while integrating retrofit. – Hardik Trivedi Apr 12 '17 at 09:51
  • Possible duplicate of [Using Retrofit in Android](http://stackoverflow.com/questions/26500036/using-retrofit-in-android) – Raut Darpan Apr 12 '17 at 09:53
  • Well i successfully parse json data from localhost server using okhttp etc..but now i need to get data from online server thats why i post this question .So i was looking for a precise answer that how to get data from my online website and to display it in my recyclerview . – Pathtaker Apr 12 '17 at 09:57

3 Answers3

0

This tutorial may definitely help you to load json to listview.

https://www.simplifiedcoding.net/retrofit-android-tutorial-to-get-json-from-server/

For recyclerview, follow this link

https://www.learn2crack.com/2016/02/recyclerview-json-parsing.html

Fathima km
  • 2,539
  • 3
  • 18
  • 26
0

first of all copy the response of your API and create your bean classes through

this site * By clicking source type to JSON * Annotation Style to GSON * Unticking useDoubleNumbers * Unticking AllowAdition Property

then copy those files to your project

Define your base Url in your Class.

make a interface named ApiController, there declare your API as

@FormUrlEncoded
@POST("your api link excluding the base url")
Call<Bean> callApi(@Field("your parameters") String name);

then in your activity write code

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    ApiController apiController = retrofit.create(ApiController.class);
    Call<Bean> result = apiController.callApi("your parameter");

    result.enqueue(new Callback<Bean>() {
        @Override
        public void onResponse(Call<Bean> call, Response<Bean> response) {

        }

        @Override
        public void onFailure(Call<Bean> call, Throwable t) {

        }
    });
Anmol317
  • 1,356
  • 1
  • 14
  • 31
0

Retrofit 2.0 GET and POST method

The link will gudie to learn the methods of retrofit2.0 for GET and POST method.

http://www.iayon.com/consuming-rest-api-with-retrofit-2-0-in-android/

You can learn retrofit to pass JsonArray and JsonObject in the following link

https://www.androidtutorialpoint.com/networking/retrofit-android-tutorial/

Sathish Kumar VG
  • 2,154
  • 1
  • 12
  • 19