我在 Android 上玩 CountDownTimer,我陷入了困境。在我的代码中,我有以下内容:
public class mCountDownTimer extends CountDownTimer{
protected boolean hasFinished = false;
public mCountDownTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
public void onFinish(){
hasFinished = true;
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
}
基本上我想知道我的 CountDownTimer 是否已经完成。但是在我想调用它的函数中,我有一些代码:
public void function(){
public boolean finished = false;
if(interrupted)
countDownTimer.cancel();
if(temporaryCountHolder == false){
countDownTimer.start();
interrupted = true;
}
}
我怎么知道我的计时器是否已经结束?我想实现一些内容:
if(countDownTimer.hasFinished == true){
Time now = new Time(); //finds the current time
now.setToNow();
String lsNow = now.format("%m-%d-%Y %I:%M:%S");
lsNow += " just Started\n";
try {
dumpToFile("StepsChanged", lsNow);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但是如果我把声明放在后面
if(temporaryCountHolder == false)
语句,那么带有 hasFinished 的 if 语句将始终评估为假。我怎样才能得到它,以便当且仅当计时器完成时我才能记录时间?