Hi in the below code am sending method as get and getting the response from and want to display that response want to set to variables.
But am not getting any response from data.am sending get method using that method am getting response .after the response is successful and then want to set that text to textviews
API.java:
public interface API {
public static final String BASE_URL="ip address";
@GET("/gateway_schedule")
Call<List<GetScheduler>> getSchedulerData();
}
Scheduler.java:
mPreset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getCCTAndIntensityValuesForPreset();
}
});
private void getCCTAndIntensityValuesForPreset() {
try {
String url = "http://XXXXXXXXXX/";
Retrofit retrofit = null;
Log.d("123", "retrofit");
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();
Log.d("123", "build();");
}
API service = retrofit.create(API.class);
Call<List<GetScheduler>> call = (Call<List<GetScheduler>>) service.getSchedulerData();
Log.d("123", "Call<List<GetScheduler>> call = service.getSchedulerData();");
call.enqueue(new Callback<List<GetScheduler>>() {
@Override
public void onResponse(Call<List<GetScheduler>> call, Response<List<GetScheduler>> response) {
if(response!=null&&response.isSuccessful()){
String getLightId=response.body().get(0).getLight_id().toString();
Toast.makeText(getApplicationContext(),"Light Id"+getLightId,Toast.LENGTH_LONG).show();
//String light_id=response.body()
}
}
@Override
public void onFailure(Call<List<GetScheduler>> call, Throwable t) {
}
});
}catch (Exception e) {Log.d("123", "Exception");}
}
Getscheduler.java:
public class GetScheduler {
@SerializedName("light_id")
private String light_id;
@SerializedName("intensity")
private int[] intensity;
@SerializedName("cct")
private int[] cct;
public String getLight_id() {
return light_id;
}
public void setLight_id(String light_id) {
this.light_id = light_id;
}
public int[] getIntensity() {
return intensity;
}
public void setIntensity(int[] intensity) {
this.intensity = intensity;
}
public int[] getCct() {
return cct;
}
public void setCct(int[] cct) {
this.cct = cct;
}
}
> call = service.getSchedulerData();
– jyothi chandra Dec 07 '18 at 09:58