Asynctask:将两个或多个值从doInBackground传递给onPostExecute

Asynctask:将两个或多个值从doInBackground传递给onPostExecute,第1张

Asynctask:将两个或多个值从doInBackground传递给onPostExecute

您可以定义一个Wrapper类,其中包含两个整数

public class Wrapper{    public int onlinePlayers;    public int maxPlayers;}

并用它代替

Integer

public class QueryServer extends AsyncTask<String, Void, Wrapper> {    protected Wrapper doInBackground(String... serverAddress) {        Log.d("QueryServer", ""+serverAddress[0]);        MCQuery mcQuery = new MCQuery("" + serverAddress[0] ,25565);        QueryResponse response = mcQuery.basicStat();        int onlinePlayers = response.getonlinePlayers(); //first vaule        int maxPlayers = response.getMaxPlayers();  //second vaule        Log.d("MCQuery", "" + onlinePlayers + " onlinePlayers");        Wrapper w = new Wrapper();        w.onlinePlayers = onlinePlayers;        w.maxPlayers = maxPlayers;        return w;    }    protected void onPostExecute(Wrapper w){        TextView onlinePlayersView = (TextView) findViewById(R.id.online_players);        onlinePlayersView.setText(""+w.onlinePlayers+"/"+ w.maxPlayers); //i need to pass Maxplayers to use it here    }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5054411.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存