Android Activity sleep 自线程更新主线程UI

原文地址:http://stackoverflow.com/questions/1520887/how-to-pause-sleep-thread-or-process-in-android

@Override

public void onClick(View v) {
    my_button.setBackgroundResource(R.drawable.icon);
    // SLEEP 2 SECONDS HERE ...
    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
         public void run() { 
              my_button.setBackgroundResource(R.drawable.defaultcard); 
         } 
    }, 2000); 
}

你可能感兴趣的:(Android)