我有一個Asynctask,它檢索兩個int值,我想將它們傳遞給onPostExecute以在視圖上顯示它們。
這裏是我的代碼:Asynctask:將兩個或更多值從doInBackground傳遞到onPostExecute
public class QueryServer extends AsyncTask <String, Void, Integer> {
protected Integer 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");
return Onlineplayers;
}
protected void onPostExecute(Integer Onlineplayers){
TextView onlinePlayersView = (TextView) findViewById(R.id.online_players);
onlinePlayersView.setText(""+Onlineplayers+"/"+ Maxplayers); //i need to pass Maxplayers to use it here
}
預先感謝您。
偉大的答案!謝謝 – Harry 2013-02-27 07:18:09
謝謝,簡單而有效 – 2014-01-27 17:49:55