线程的一个基本应用:联网进度条对话框
线程总给我一种云里雾里的感觉。感觉她是那么深奥,那么强大。总让我望而生畏。-----杯具
public class HelloXML extends Activity { private static final int MESSAGETYPE_01 = 0x0001; private ProgressDialog progressDialog = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.main); progressDialog = ProgressDialog.show(HelloXML.this, "下载", "正在下载,请稍候!"); new Thread() { public void run() { try { // 连接网络获取数据 } catch (Exception e) { // 在GUI显示错误提示 // tv.setText("Error: " + e.getMessage()); } Message msg_listData = new Message(); msg_listData.what = MESSAGETYPE_01; handler.sendMessage(msg_listData); } }.start(); } private Handler handler = new Handler() { public void handleMessage(Message message) { switch (message.what) { case MESSAGETYPE_01: //刷新UI,显示数据,并关闭进度条 progressDialog.dismiss(); //关闭进度条 break; } } };}
?