1. Try using postdelayed (Runnable A, int time), because post puts the message in Looper and returns, but there is no other message in the looper that will be taken out immediately, so it is possible to do the operation in the run, instead of refreshing the button in time.
2. In addition, the time-consuming operation of this practice is still done by the UI thread: Instead of you think of another thread.
It is advisable to use the following method:
Defines a thread.
Class MyThread extends thread{
Handler Mhandler;
Boolean Boo;
Public MyThread (Handler Handler) {
Mhandler = handler;
}
public void Setboo (Boolean b) {boo = b;}
Publid void Run () {
if (boo) {
Getweatherinfo ();//time-consuming operation
Analyzing ();//time-consuming operation
Mhandler.post (New Runnable () {
public void Run () {
Setweather ();//Update UI
}
);//Update UI
Boo = true;
}
}
}
When you handle a click event:
Surebutton.setonclicklistener (New Button.onclicklistener () {
public void OnClick (view view) {
Setboo (TRUE);
Mythread.start ();
}
});
In the activity:
MyThread MyThread = new MyThread (Mhandler);
Android Handler calls the Post method to block