-> 用户点击一个按钮(实际上是一张卡片),我通过改变这个按钮的背景来显示它:
thisbutton.setBackgroundResource(R.drawable.icon);
->在1秒钟后,我需要通过更改按钮的背景颜色来返回到其先前的状态:
thisbutton.setBackgroundResource(R.drawable.defaultcard);
-> 我曾尝试使用以下代码在这两行代码之间暂停线程:
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
然而,这并不起作用。也许我需要暂停的是进程而不是线程?我还尝试过以下方法(但它不起作用):
new Reminder(5);
使用这个:
public class Reminder {
Timer timer;
public Reminder(int seconds) {
timer = new Timer();
timer.schedule(new RemindTask(), seconds*1000);
}
class RemindTask extends TimerTask {
public void run() {
System.out.format("Time's up!%n");
timer.cancel(); //Terminate the timer thread
}
}
}
如何暂停/休眠线程或进程?
(!conditionCheck()) {}
通常是被不鼓励的。 - Miserable Variable