第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在改造之外打印時值為空的數(shù)組列表

在改造之外打印時值為空的數(shù)組列表

慕慕森 2022-05-25 17:48:29
為什么我的數(shù)組列表的值為空?當它在改造之外打印時,即使我已經(jīng)聲明了公共變量List<Profile> profileList = new ArrayList<Profile>();我想要在改造之外打印值數(shù)組列表但沒有工作。當在改造內(nèi)打印值數(shù)組列表時,它起作用了。這是我的代碼你好.javaList<Profile> profileList = new ArrayList<Profile>();apiService.getGetlistuser("getlistuser").enqueue(new Callback<ResponseDaftar>() {        @Override        public void onResponse(Call<ResponseDaftar> call, Response<ResponseDaftar> response) {            if (response.isSuccessful()) {                List<GetlistuserItem> getlistuserItemList = response.body().getGetlistuser();                for (int i = 0; i < getlistuserItemList.size(); i++) {                    profileList.add(new Profile(                            getlistuserItemList.get(i).getUserID(),                            getlistuserItemList.get(i).getNickname()                    ));                }    /*       is working      for (Profile p : profileList){          Log.i("info", p.getUserid() + '\n' + p.getNickname());      }     */            }        }    });    // my value is empty    for (Profile p : profileList){        Log.i("info", p.getUserid() + '\n' + p.getNickname());    }改造接口@POST("GetListNews.php")    @FormUrlEncoded    Call<ResponseDaftar> getGetlistuser(@Field("TableName") String paramTable);
查看完整描述

3 回答

?
一只甜甜圈

TA貢獻1836條經(jīng)驗 獲得超5個贊

您必須檢查響應方法 (您評論的地方)中的數(shù)據(jù),因為加載響應需要一些時間,有時下一條語句會在響應可用之前運行。



查看完整回答
反對 回復 2022-05-25
?
明月笑刀無情

TA貢獻1828條經(jīng)驗 獲得超4個贊

從服務器獲取數(shù)據(jù)可能會有一些延遲。


因此,您可以添加一個listener將在您的代碼打印列表被填充后觸發(fā)(如果您的打印代碼將在另一個類中),或者如果它在同一個類中,則調(diào)用另一個方法。


示例代碼


List<Profile> profileList = new ArrayList<Profile>();

public void getData(){

    final Listener listener = new Listener() {

        @Override

        public void onDataReceived() {

            //print command goes here

        }

    }

    apiService.getGetlistuser("getlistuser").enqueue(new Callback<ResponseDaftar>() {

        @Override

        public void onResponse(Call<ResponseDaftar> call, Response<ResponseDaftar> response) {

            if (response.isSuccessful()) {

                List<GetlistuserItem> getlistuserItemList = response.body().getGetlistuser();

                for (int i = 0; i < getlistuserItemList.size(); i++) {

                    profileList.add(new Profile(

                            getlistuserItemList.get(i).getUserID(),

                            getlistuserItemList.get(i).getNickname()

                    ));

                }

                printData(); //if it is in same class

                if(listener != null) 

                    listener.onDataReceived(); //if it is going to happen in another class

    /*

      is working

      for (Profile p : profileList){

          Log.i("info", p.getUserid() + '\n' + p.getNickname());

      }

    */



                }

            }


        });


    // my value is empty

    for (Profile p : profileList){

        Log.i("info", p.getUserid() + '\n' + p.getNickname());

    }

}


public void printData(){

    for (Profile p : profileList){

        Log.i("info", p.getUserid() + '\n' + p.getNickname());

    }

}


// this will be going to make in separate file 

interface Listener{

    void onDataReceived();

}


查看完整回答
反對 回復 2022-05-25
?
慕勒3428872

TA貢獻1848條經(jīng)驗 獲得超6個贊

您正在閱讀 profileList 在填充之前。



查看完整回答
反對 回復 2022-05-25
  • 3 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號