我在Android上玩了CountDownTimer,我陷入了一种两难的境地。在我的代码,我有以下几点:查找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)
语句,那么if语句与hasFinished的计算结果始终是假的。我怎样才能得到它,以便当且仅当定时器完成时才能记录时间?
你能告诉你究竟是如何使用'如果(countDownTimer.hasFinished ==真)后''如果(temporaryCountHolder ==假)'? – Vinay 2013-04-11 06:25:38
@JJPA我刚刚添加了我如何使用countDownTimer.hasFinished ==真正的方法 – user1567909 2013-04-11 06:27:57
它是否后来'if(temporaryCountHolder == false){countDownTimer.start(); interrupted = true;}'或在此语句中? – Vinay 2013-04-11 06:30:05