How to call data from an API into a spinner? - java

I want to show a district list in a spinner, and i am getting that data through an API.
Here is an example of the response.
{
"districts": [
{
"district": "ANANTNAG"
},
{
"district": "BADGAM"
},
{
"district": "BANDIPORA"
},
{
"district": "BARAMULLA"
},
{
"district": "DODA"
},
{
"district": "GANDERBAL"
},
{
"district": "JAMMU"
},
{
"district": "KARGIL"
},
{
"district": "KATHUA"
},
{
"district": "KISHTWAR"
},
{
"district": "KULGAM"
},
{
"district": "KUPWARA"
},
{
"district": "LEH LADAKH"
},
{
"district": "POONCH"
},
{
"district": "PULWAMA"
},
{
"district": "RAJAURI"
},
{
"district": "RAMBAN"
},
{
"district": "REASI"
},
{
"district": "SAMBA"
},
{
"district": "SHOPIAN"
},
{
"district": "SRINAGAR"
},
{
"district": "UDHAMPUR"
},
{
"district": "JAMMU AND KASHMIR"
}
],
"Request_type": "districts",
"responseCode": "Success"
}
After that, I created 2 schemapojo class for response and dataList as well.
Then, I am calling this into a class but its not working!! I don't have any idea how to call an API and set the response data into a spinner.
Please help
private void getdistricts(String state) {
JSONObject mJobj = new JSONObject();
try {
mJobj.put("state", state);
mJobj.put(REQUEST, "districts");
} catch (JSONException e) {
e.printStackTrace();
}
Call<districtresponse> call = RetrofitClient.getInstance().getApi().getDistrict(mJobj);
call.enqueue(new Callback<districtresponse>() {
#Override
public void onResponse(Call<districtresponse> call, Response<districtresponse> response) {
String status = response.body().getResponseCode();
if (status.equalsIgnoreCase("Success")){
district_list = response.body().getDistricts();
districts = new ArrayAdapter<String>(this,R.layout.dist_list,district_list);
}
}
#Override
public void onFailure(Call<districtresponse> call, Throwable t) {
}
});
}
Here in code district_List variable is for a second model class where all district List is available.
I tried a different process from youtube but none of that worked !!

Change code
districts = new ArrayAdapter<String>(this,R.layout.dist_list,district_list);
To this
ArrayAdapter adapter
= new ArrayAdapter(
this,
android.R.layout.simple_spinner_item,
districts);
// set simple layout resource file
// for each item of spinner
adapter.setDropDownViewResource(
android.R.layout
.simple_spinner_dropdown_item);
// Set the ArrayAdapter (ad) data on the
// Spinner which binds data to spinner
spino.setAdapter(adapter);

You can also try like this
ArrayList<String> stringArrayList = null; //Create A global Variable
Call<Example> call = RetrofitClient.getInstance().getApi().getDistrict();
call.enqueue(new Callback<Example>() {
#Override
public void onResponse(Call<Example> call, Response<Example> response) {
if (response.code() == 200) {
ArrayList<District> districts = (ArrayList<District>) response.body().getDistricts();
for (int i = 0; i < districts.size(); i++) {
stringArrayList.add(districts.get(i).getDistrict());
}
}
}
#Override
public void onFailure(Call<Example> call, Throwable t) {
}
});
ArrayAdapter arrayAdapter = new ArrayAdapter(this,R.layout.dist_list,district_list,stringArrayList);
arrayAdapter.setDropDownViewResource(R.layout.dist_list,district_list);
yourSpinner.setAdapter(arrayAdapter);
And here create a model like this
Example Model Class
public class Example {
#SerializedName("districts")
#Expose
private List<District> districts = null;
#SerializedName("Request_type")
#Expose
private String requestType;
#SerializedName("responseCode")
#Expose
private String responseCode;
public List<District> getDistricts() {
return districts;
}
public void setDistricts(List<District> districts) {
this.districts = districts;
}
public String getRequestType() {
return requestType;
}
public void setRequestType(String requestType) {
this.requestType = requestType;
}
public String getResponseCode() {
return responseCode;
}
public void setResponseCode(String responseCode) {
this.responseCode = responseCode;
}
}
District Model Class
public class District {
#SerializedName("district")
#Expose
private String district;
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
}
I just hope your problem is solved using this

Related

Handling a network request response in android

I created an android application to handle network requests using Volley API. I have managed to get a response from the server but I am failing to loop through the different objects of the result JSON and when I add data to a Listview it is only giving me the application's package name with a number added at the end.
This is the response that I want to handle.
{
"list": [
{
"dt": 1637172000,
"main": {
"temp": 301.79,
"feels_like": 300.34,
"temp_min": 298.24,
"temp_max": 301.79,
"pressure": 1008,
"sea_level": 1008,
"grnd_level": 854,
"humidity": 20,
"temp_kf": 3.55
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}
],
"clouds": {
"all": 7
},
"wind": {
"speed": 3.77,
"deg": 46,
"gust": 8.98
},
"visibility": 10000,
"pop": 0,
"sys": {
"pod": "n"
},
"dt_txt": "2021-11-17 18:00:00"
}
]
}
The object model and its fields
public class WeatherReportModel {
private int dt;
private JSONObject main;
private JSONArray weather;
private JSONObject clouds;
private JSONObject wind;
private int visibility;
private double pop;
private JSONObject sys;
private String dt_txt;
public WeatherReportModel(
int dt,
JSONObject main,
JSONArray weather,
JSONObject clouds,
JSONObject wind,
int visibility,
double pop,
JSONObject sys,
String dt_txt) {
this.dt = dt;
this.main = main;
this.weather = weather;
this.clouds = clouds;
this.wind = wind;
this.visibility = visibility;
this.pop = pop;
this.sys = sys;
this.dt_txt = dt_txt;
}
}
This is call back function which fetches the responses and add to the Model's object
public void getWeather(VolleyResponseListener forecast) {
List<WeatherReportModel> weatherReportModels = new ArrayList<>();
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONArray weather_list = response.getJSONArray("list");
// get the first item
for (int i = 0; i < weather_list.length(); i++) {
WeatherReportModel one_day_weather = new WeatherReportModel();
JSONObject first_day_from_api = (JSONObject) weather_list.get(i);
one_day_weather.setDt(first_day_from_api.getInt("dt"));
one_day_weather.setMain(first_day_from_api.getJSONObject("main"));
one_day_weather.setWeather(first_day_from_api.getJSONArray("weather"));
one_day_weather.setClouds(first_day_from_api.getJSONObject("clouds"));
one_day_weather.setWind(first_day_from_api.getJSONObject("wind"));
one_day_weather.setVisibility(first_day_from_api.getInt("visibility"));
one_day_weather.setPop(first_day_from_api.getLong("pop"));
one_day_weather.setSys(first_day_from_api.getJSONObject("sys"));
one_day_weather.setDt_txt(first_day_from_api.getString("dt_txt"));
weatherReportModels.add(one_day_weather);
}
forecast.onResponse(weatherReportModels);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
//get the property call consolidated weather
MySingleton.getInstance(context).addToRequestQueue(request);
}
Usually, ArrayAdapter when used like this will try to use toString() function to get the value and display it. Try to override the toString in the
WeatherReportModel and try again.

How to create pojo class of Object of ArrayList from REST API response?

I'm working on project in which I have to implement on API. This API repsonse is objects of ArrayList. Can you please help me with creating its POJO class and if possible its implementation. I'm using retrofit2 & GSON.
As shown in following JSON schema, brand names will be added in brandsonly by admin, and it will be added in allorders as a arraylist which have multiple sub-objects.
Like, if admin add Redmi in the brandsonly then it will create Redmi[] in the allorders
{
"status": "success",
"brandsonly": [
{
"_id": "",
"brandname": "SAMSUNG",
},
{
"_id": "",
"brandname": "VIVO",
},
{
"_id": "",
"brandname": "NOKIA"
},
{
"_id": "",
"brandname": "IPHONE",
}
],
"allorders": {
"SAMSUNG": [],
"VIVO": [],
"NOKIA": [],
"IPHONE": [
{
"_id": "",
"order_id": "",
"__v": 0,
"adminconfirmation": 1,
"finalpricetodeduct": 30950
},
{
"_id": "",
"order_id": "",
"__v": 0,
"adminconfirmation": 1,
"finalpricetodeduct":
}
]
},
}
My Retrofit call from activity:
final AllOrdersResponse allOrdersResponse = new AllOrdersResponse(userID);
Call<AllOrdersResponse> responseCall = retrofit_interface.allOrderResponse(allOrdersResponse, "Bearer " + AuthToken);
responseCall.enqueue(new Callback<AllOrdersResponse>() {
#Override
public void onResponse(#NotNull Call<AllOrdersResponse> call, #NotNull Response<AllOrdersResponse> response) {
AllOrdersResponse response1 = response.body();
}
#Override
public void onFailure(#NotNull Call<AllOrdersResponse> call, #NotNull Throwable t) {
if (t instanceof SocketTimeoutException)
Toast.makeText(context, "Socket Time out. Please try again.", Toast.LENGTH_LONG).show();
else
Toast.makeText(context, t.toString(), Toast.LENGTH_LONG).show();
}
});
I dont think a POJO schema would work in this instance as it will always change. It would be much better is the allorders was the same as brandsonly a JSON Array of JSON Array
However, if that cannot be changed have a look at the below.
final AllOrdersResponse allOrdersResponse = new AllOrdersResponse(userID);
Call<AllOrdersResponse> responseCall = retrofit_interface.allOrderResponse(allOrdersResponse, "Bearer " + AuthToken);
responseCall.enqueue(new Callback<AllOrdersResponse>() {
#Override
public void onResponse(#NotNull Call<AllOrdersResponse> call, #NotNull Response<AllOrdersResponse> response) {
AllOrdersResponse response1 = response.body();
List<String> brands = new ArrayList<>();
List<Map<String, Product>> products = new ArrayList<>();
JSONObject jsonObject = new JSONObject(response1);
for(JSONObject brand : jsonObject.get("brandsonly")){
brands.add(brand.getvalue("brandname"));
}
if(brands.size= > 0){
for(String brandname: brands){
HashMap<String, Product> tempHash = new HashMap<>();
JSONArray temp = jsonObject.getJSONArray(brandname);
foreach(JSONObject x : temp){
Product product = new Product();
product.FromJSONObject(x);
temp.put(brandname, product);
}
products.add(tempHash);
}
}
}
#Override
public void onFailure(#NotNull Call<AllOrdersResponse> call, #NotNull Throwable t) {
if (t instanceof SocketTimeoutException)
Toast.makeText(context, "Socket Time out. Please try again.", Toast.LENGTH_LONG).show();
else
Toast.makeText(context, t.toString(), Toast.LENGTH_LONG).show();
}
});
So you have a list of BandNames with a value of each product.
I would also recommend looking at jsonschema2.pojo

How to fetch values of sub array inside the main array?

I am new at programming. I just want to ask if there is a possible way of fetching values of sub arrays from main array? I have this problem of fetching the values from sub array entitled "subresult". I have code of getting values from an array but it seems that it only gets the outer array and disregard the inner array. It is sad that I have no luck in this. Please respect my question because I'm just a beginner. Hoping an answer from you guys. Thank you!
JSON:
{
"result":[
{
"commonname":"Tamaraw",
"subresult":[
{
"latitude":"13.088847376649245",
"longitude":"121.0535496566772",
"province":"Mindoro"
},
{
"latitude":"14.898346071682198",
"longitude":"121.42616213302608",
"province":"General nakar"
},
{
"latitude":"14.44133541176629",
"longitude":"120.45936525802608",
"province":"Bataan"
}
]
},
{
"commonname":"Philippine Tarsier",
"subresult":[
{
"latitude":"9.810806171435631",
"longitude":"124.26143093023506",
"province":"Bohol"
}
]
},
{
"commonname":"Philippine Eagle",
"subresult":[
{
"latitude":"7.2396901503428",
"longitude":"125.44315069027664",
"province":"Davao City"
}
]
},
{
"commonname":"Visayan Warty Pig",
"subresult":[
{
"latitude":"9.651642644962154",
"longitude":"122.84131398239595",
"province":"Panay And Negros"
}
]
},
{
"commonname":"Philippine Fresh Water Crocodile",
"subresult":[
{
"latitude":"13.093068957060206",
"longitude":"121.06598892373722",
"province":"Mindoro"
}
]
},
{
"commonname":"Walden's Hornbill",
"subresult":[
{
"latitude":"10.071930427284427",
"longitude":"125.59779391691245",
"province":"Camiguin Sur and Dinagat Island"
},
{
"latitude":"14.656674396646768",
"longitude":"121.05812014083858",
"province":"Quezon"
}
]
},
{
"commonname":"Philippine Cockatoo",
"subresult":[
{
"latitude":"9.380944735295179",
"longitude":"118.38456063371927",
"province":"Palawan"
},
{
"latitude":"15.491670747921509",
"longitude":"120.94052188562534",
"province":"Cabanatuan City"
},
{
"latitude":"15.378556159943873",
"longitude":"121.39594973068233",
"province":"Dingalan"
}
]
},
{
"commonname":"Negros Bleeding-heart",
"subresult":[
{
"latitude":"9.551081019434731",
"longitude":"123.09185859510103",
"province":"Negros and Panay"
}
]
},
{
"commonname":"Philippine naked-backed fruit bat",
"subresult":[
{
"latitude":"9.646007526813666",
"longitude":"122.85255472090171",
"province":"Negros"
}
]
},
{
"commonname":"Philippine Forest Turtle",
"subresult":[
{
"latitude":"9.35368808473656",
"longitude":"118.36544272849846",
"province":"Palawan"
}
]
},
{
"commonname":"Dinagat bushy-tailed Cloud Rat",
"subresult":[
{
"latitude":"10.100726050965035",
"longitude":"125.59963979398412",
"province":"Dinagat Island"
}
]
},
{
"commonname":"Hawksbill Sea Turtle",
"subresult":[
{
"latitude":"6.984796116278719",
"longitude":"122.02642351890961",
"province":"Zamboanga"
}
]
},
{
"commonname":"Philippine Spotted Deer",
"subresult":[
{
"latitude":"16.229997551983594",
"longitude":"120.52623997214562",
"province":"Baguio"
}
]
}
]
}
Java code:
public JSONArray result;
public static final String JSON_ARRAY = "result";
public static final String TAG_COMMONNAME= "commonname";
public void getData(){
//Creating a string request
StringRequest stringRequests = new StringRequest(Config.DATA_URL,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
JSONObject jo = null;
try {
//Parsing the fetched Json String to JSON Object
jo = new JSONObject(response);
//Storing the Array of JSON String to our JSON Array
result = jo.getJSONArray(JSON_ARRAY);
//Calling method getStudents to get the students from the JSON Array
getAnimals(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
//Creating a request queue
RequestQueue requestQueue2 = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue2.add(stringRequests);
}
public void getAnimals(JSONArray ja){
//Traversing through all the items in the json array
for(int i=0;i<ja.length();i++){
try {
//Getting json object
json = ja.getJSONObject(i);
//Adding the name of the student to array list
students.add(json.getString(TAG_COMMONNAME));
} catch (JSONException e) {
e.printStackTrace();
}
}

Parse JSON to fetch all the details using Asynctask

{
"response_code": 200,
"debit": 3,
"position": "Train has reached Destination and late by 5 minutes",
"train": {
"number": "12046",
"name": "CDG NDLS SHTBDI"
},
"route": [
{
"no": 1,
"day": 0,
"station": {
"name": "CHANDIGARH",
"code": "CDG"
},
"has_arrived": false,
"has_departed": true,
"distance": 0,
"scharr": "Source",
"schdep": "12:00",
"actarr": "00:00",
"actdep": "12:00",
"scharr_date": "19 Nov 2015",
"actarr_date": "19 Nov 2015",
"latemin": 0
},
{
"no": 2,
"day": 0,
"station": {
"name": "AMBALA CANT JN",
"code": "UMB"
},
"has_arrived": true,
"has_departed": true,
"distance": 67,
"scharr": "12:40",
"schdep": "12:42",
"actarr": "12:40",
"actdep": "12:42",
"scharr_date": "19 Nov 2015",
"actarr_date": "19 Nov 2015",
"latemin": 0
},
{
"no": 3,
"day": 0,
"station": {
"name": "NEW DELHI",
"code": "NDLS"
},
"has_arrived": true,
"has_departed": false,
"distance": 265,
"scharr": "15:25",
"schdep": "Destination",
"actarr": "15:30",
"actdep": "00:00",
"scharr_date": "19 Nov 2015",
"actarr_date": "19 Nov 2015",
"latemin": 5
}
]
}
public class TrainStatus {
public static int responseCode;
private int serialNo;
private String scheduleArrival;
private String actualArrival;
public static String station;
public static int debit;
private String statusOfArrival;
private boolean hasArrived;
private boolean hasDeparted;
private int latemin;
private String actualArrivalDate;
private String scheduleArrivalDate;
public static String position;
public String name;
public String getName()
{
return getName();
}
public void setName(String name)
{
this.name=name;
}
public boolean isHasArrived()
{
return hasArrived;
}
public void setHasArrived(boolean hasArrived)
{
this.hasArrived = hasArrived;
}
public boolean isHasDeparted()
{
return hasDeparted;
}
public void setHasDeparted(boolean hasDeparted)
{
this.hasDeparted = hasDeparted;
}
public int getLatemin()
{
return latemin;
}
public void setLatemin(int latemin)
{
this.latemin = latemin;
}
public void setSerialNo(int serialNo)
{
this.serialNo = serialNo;
}
public String getScheduleArrival()
{
return scheduleArrival;
}
public void setScheduleArrival(String scheduleArrival)
{
this.scheduleArrival = scheduleArrival;
}
public String getActualArrival()
{
return actualArrival;
}
public void setActualArrival(String actualArrival)
{
this.actualArrival = actualArrival;
}
public String getStation()
{
return station;
}
public void setStation(String station)
{
this.station = station;
}
public String getStatusOfArrival()
{
return statusOfArrival;
}
public void setStatusOfArrival(String statusOfArrival)
{
this.statusOfArrival = statusOfArrival;
}
public String getActualArrivalDate()
{
return actualArrivalDate;
}
public void setActualArrivalDate(String actualArrivalDate)
{
this.actualArrivalDate = actualArrivalDate;
}
public String getScheduleArrivalDate()
{
return scheduleArrivalDate;
}
public void setScheduleArrivalDate(String scheduleArrivalDate)
{
this.scheduleArrivalDate = scheduleArrivalDate;
}
}
public class TrainStatusParser {
public static List<TrainStatus> parseFeed(String content){
try
{
JSONObject jsonObject = new JSONObject(content);
List<TrainStatus> trainList = new ArrayList<>();
TrainStatus.responseCode = jsonObject.getInt("response_code");
TrainStatus.position = jsonObject.getString("position");
TrainStatus.debit=jsonObject.getInt("debit");
JSONArray route = jsonObject.getJSONArray("route");
for(int i=0;i<route.length();i++)
{
JSONObject routeObject = route.getJSONObject(i);
TrainStatus trainStatus = new TrainStatus();
if (jsonObject.has("station"))
{
JSONObject addressObject = jsonObject.getJSONObject("station");
trainStatus.name=addressObject.getString("name");
}
trainStatus.setSerialNo(routeObject.getInt("no"));
trainStatus.setScheduleArrival(routeObject.getString("scharr"));
trainStatus.setActualArrival(routeObject.getString("actarr"));
trainStatus.setStatusOfArrival(routeObject.getString("status"));
trainStatus.setHasArrived(routeObject.getBoolean("has_arrived"));
trainStatus.setHasDeparted(routeObject.getBoolean("has_departed"));
trainStatus.setLatemin(routeObject.getInt("latemin"));
trainStatus.setActualArrivalDate(routeObject.getString("actarr_date"));
trainStatus.setScheduleArrivalDate(routeObject.getString("scharr_date"));
trainList.add(trainStatus);
}
return trainList;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}
Everything is correctly fetched except station name
Try this following code.
for(int i=0;i<route.length();i++) {
JSONObject routeObject = route.getJSONObject(i);
TrainStatus trainStatus = new TrainStatus();
JSONObject jsonObject_station = routeObject.getJSONObject("station");
String stationname = jsonObject_station.getString("name");
String code = jsonObject_station.getString("code");
Log.d("checkvalue", " " + stationname + " " + code);
trainStatus.setSerialNo(routeObject.getInt("no"));
trainStatus.setScheduleArrival(routeObject.getString("scharr"));
trainStatus.setActualArrival(routeObject.getString("actarr"));
trainStatus.setStatusOfArrival(routeObject.getString("status"));
trainStatus.setHasArrived(routeObject.getBoolean("has_arrived"));
trainStatus.setHasDeparted(routeObject.getBoolean("has_departed"));
trainStatus.setLatemin(routeObject.getInt("latemin"));
trainStatus.setActualArrivalDate(routeObject.getString("actarr_date"));
trainStatus.setScheduleArrivalDate(routeObject.getString("scharr_date"));
trainList.add(trainStatus);
}
Use a library from Google call GSON
In your posted code for parsing each route, you have this:
JSONObject routeObject = route.getJSONObject(i);
TrainStatus trainStatus = new TrainStatus();
if (jsonObject.has("station"))
{
JSONObject addressObject = jsonObject.getJSONObject("station");
trainStatus.name=addressObject.getString("name");
}
Looks like a typo here is causing your problems. You're calling jsonObject.has("station") when you should instead be calling routeObject.has("station"). Similarly, inside the if statement you should change jsonObject.getJSONObject("station") to routeObject.getJSONObject("station").

Web Service retrofit parsing

what is wrong with this retrofit ? request is success but no values are get
this is how my json looks like
[
{
"msg": "test",
"time": "2017-06-20 00:39:31",
"kind": "txt"
},
{
"msg": "مرحبا يا برو",
"time": "2017-06-20 00:40:02",
"kind": "txt"
},
{
"msg": "url",
"time": "2017-06-20 01:57:12",
"kind": "img"
},
{
"msg": "url",
"time": "2017-06-20 01:58:54",
"kind": "video"
}
]
AllMessagesResponse class
public class AllMessagesResponse {
public ArrayList<MessagesInfo> getMessagesInfos() {
return messagesInfos;
}
private ArrayList<MessagesInfo>messagesInfos=new ArrayList<>();
}
MessageInfo class
public class MessagesInfo{
#SerializedName("time")
private String time;
#SerializedName("msg")
private String msgs;
#SerializedName("kind")
private String kind;
#SerializedName("sender")
private String senderID;
public String getTime() {
return time;
}
public String getMsgs() {
return msgs;
}
public String getKind() {
return kind;
}
public String getSenderID() {
return senderID;
}
}
API class
#POST("chat/veiwPeerToPeer.php")
Call<AllMessagesResponse>getMessages(#Body AllMessages allMessages);
Main Activity class
AllMessages allMessages=new AllMessages();
allMessages.senderID=MainActivity.userId;
allMessages.receiverID=receiverId;
WebService.getInstance().getApi().getMessages(allMessages).enqueue(new Callback<AllMessagesResponse>() {
#Override
public void onResponse(Call<AllMessagesResponse> call, Response<AllMessagesResponse> response) {
AllMessagesResponse allMessagesResponse=response.body();
setTitle(String.valueOf(allMessagesResponse.getMessagesInfos().size()));
}
#Override
public void onFailure(Call<AllMessagesResponse> call, Throwable t) {
}
});
onResponse is working but I get no values
You don't need another pojo for list you can directly request for list Retrofit directly provide list.
Call<List<POJO>>
I fetch the same JSON response like you did. SEE URL
apiInterface = new Retrofit.Builder()
.baseUrl(BASE_URL_ANDROIDHIVE)
.addConverterFactory(GsonConverterFactory.create())
.build().create(ApiInterface.class);
final Call<List<AndroidHive>> hiveCall = apiInterface.getAllMovies();
hiveCall.enqueue(new Callback<List<AndroidHive>>() {
#Override
public void onResponse(Call<List<AndroidHive>> call, Response<List<AndroidHive>> response) {
if (response.isSuccessful()) {
progressDialog.dismiss();
List<AndroidHive> hiveList = response.body();
tv_retrofit.setText("Title : " + hiveList.get(3).getTitle() + "\n Image : " + hiveList.get(3).getImage() + "\n Rating : " + hiveList.get(3).getRating() + " \n Release Year : " + hiveList.get(3).getReleaseYear() + "\n Gener : " + hiveList.get(3).getGenre());
} else {
Toast.makeText(getActivity(), "Response Failed Code : " + response.message(), Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
}
#Override
public void onFailure(Call<List<AndroidHive>> call, Throwable t) {
System.out.println(t.getStackTrace().toString());
progressDialog.dismiss();
}
});

Categories

Resources