post方式能解决UI线程阻塞问题,但是代码的可读性较差。
一:看程序
private class testTask extends AsyncTask<String, Void, Integer> { protected Integer doInBackground(String... arg0) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } int sum = 10; return 10; } protected void onPostExecute(Integer sum) { button2.setText("" + sum); } }
原文地址:http://blog.csdn.net/u013628152/article/details/43795581