小编Gul*_*dav的帖子

无法在call.enqueue中的for循环之外获取ArrayList

我想从Retrofit中的call.enqueue方法的for循环中获取ArrayList数据。

如何在call.enqueue方法之外访问列表?

一切正常。打印列表大小时,我会获得所需的价值。唯一的问题是我无法从call.enqueue方法外部访问值。

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();

        }
    });

}
Run Code Online (Sandbox Code Playgroud)

我想在call.enqueue方法之外访问ArrayList。

java android retrofit retrofit2

2
推荐指数
1
解决办法
58
查看次数

标签 统计

android ×1

java ×1

retrofit ×1

retrofit2 ×1