private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case GET2CODE_SUCCESS: dialog.dismiss(); set2CodeShow(); break; case CONN_FAILED: dialog.dismiss(); set2CodeShow(); Toast.makeText(GoodsInfo.this, "连接失败", Toast.LENGTH_SHORT) .show(); break; default: break; } } };mHandler.sendEmptyMessage(GET2CODE_SUCCESS);或者创建一个消息对象,Message msg = new Message();msg.what=GET2CODE_SUCCESS;然后通过mHandler.sendMessage(msg);来发送消息给消息队列,当然也可以发送对象数据,即用msg.obj= Object来发送对象。
Android更新UI的两种方法——handler与runOnUiThread()
原文地址:http://blog.csdn.net/u010687392/article/details/43890565