自定义Handler 线程发送消息

Handler myHandler = new Handler() { 
        public void handleMessage(Message msg) { 
            switch (msg.what) { 
            case 0: 
                textView1.setText(html); 
                progressDialog.dismiss(); 
                break; 
            case 1: 
                textView1.setText("《致我们终将逝去的青春》"); 
                progressDialog.dismiss(); 
                break; 
            } 
            super.handleMessage(msg); 
        } 
}; 
 
 
 
new Thread() {  
            public void run() {  
                Message msg = myHandler.obtainMessage();  
                try {  
                    html = HttpUtil.fromHtml(HttpUtil  
                            .getHtml("http://yuncode.net"));  
                    msg.what = 0;  
                } catch (Exception e) {  
                    e.printStackTrace();  
                    msg.what = 1;  
                }  
    
                myHandler.sendMessage(msg);  
            }  
}.start();

你可能感兴趣的:(handler,消息,发送)