首页 > 解决方案 > 我在将数组列表返回到 downloadsurl() 方法时遇到问题

问题描述

我可以在 for 循环中为 URL 列表敬酒,但是当我尝试使用该downloadurls()方法时,downloadlist 变量为空。

public static List<String> downloadUrls(Context context){

     final List<DownloadData> downloadDataList= new ArrayList<>();
     final List<String> downloadList= new ArrayList<>();

    if (NetworkChangeReceiver.isNetworkConnected()){
        Integer customerId = Integer.parseInt(AppPreference.getInstance(context).getString(PrefKey.CUSTOMER_ID));
        ApiClient.getInstance().getApiInterface().getDownloadData(customerId).enqueue(new Callback<List<DownloadData>>() {
            @Override
            public void onResponse(Call<List<DownloadData>> call, Response<List<DownloadData>> response) {

                if (response.isSuccessful() && response.body() != null){

                        downloadDataList.clear();
                        downloadDataList.addAll(response.body());

                        for (int i= 0; i<downloadDataList.size(); i++){
                            downloadList.clear();
                            downloadList.add(downloadDataList.get(i).getFileUrlData().getFile());
                            Toast.makeText(context, downloadList.toString(), Toast.LENGTH_SHORT).show();
                        }
                }
            }

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

            }
        });


    }
    else {
        Toast.makeText(context, "Please turn on Internet data bundles", Toast.LENGTH_SHORT).show;
    }



    return downloadList;
}

标签: java

解决方案


推荐阅读