Handler的demo
private Runnable mRunnable = new Runnable() {
public void run() {
while (true) {
if (mThread == null) {
return;
}
try {
Thread.sleep(1000);
mHandler.sendEmptyMessage(0x11);
mHandler.sendEmptyMessage(0x12);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch(msg.what){
case 0x11:
refreshUI_1();
break;
case 0x12:
refresh_2();
break;
}
}
};
private void refreshUI_1() {
if(count1 == 10){
edt1.setText("线程1 结束");
mThread = null;
return;
}
edt1.setText(count1+"");
count1 ++;
}
private void refresh_2(){
if(count2 == 100){
edt2.setText("线程2 结束");
mThread = null;
return;
}
edt2.setText(count2+"");
count2 += 10;
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。