I want to get ArrayList data out of for loop from call.enqueue method in Retrofit.
how to access lists outside of call.enqueue mehtod?
Everything is working fine. When printing list size I'm getting value what I want. The only problem is i can't access values from outside of call.enqueue method.
private void getSchoolList() {
final Call<List<DanceSchool>> call = RetrofitClient.getInstance().getApi().getDanceSchools();
call.enqueue(new Callback<List<DanceSchool>>() {
@Override
public void onResponse(Call<List<DanceSchool>> call, Response<List<DanceSchool>> response) {
if(!response.isSuccessful()) {
Toast.makeText(ListActivity.this, "Response Code: " + response.code(), Toast.LENGTH_SHORT).show();
}
List<DanceSchool> danceSchools = response.body();
for(DanceSchool danceSchool:danceSchools){
schoolNameList.add(danceSchool.getSchool_name());
dayList.add(danceSchool.getDays());
timingList.add(danceSchool.getSun_timing());
contactNoList.add(danceSchool.getContact_no());
addressList.add(danceSchool.getAddress());
}
}
@Override
public void onFailure(Call<List<DanceSchool>> call, Throwable t) {
Toast.makeText(ListActivity.this, "Failure: "+t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
I want to access ArrayList outside of the call.enqueue method.