我需要在最初的60秒内启动计时器,但是当我按下按钮时,设置5秒或者只是取消但是它不起作用:
temp = new CountDownTimer(60000, 1000) {
Button acabar= (Button) findViewById(R.id.button_abandonar);
public void onTick(long millisUntilFinished) {
int seg = (int) (millisUntilFinished /1000);
if(seg<10){
veces.setText("0" + seg);
}else{
veces.setText("" + seg);
}
}
public void onFinish() {
//something
}
};
if(v.getId()==R.id.view_pulsar){
//Here I start temp and I do more things, but I don't show this code because is not relevant to this problem
}else if(v.getId()==R.id.button_abandonar){
temp.cancel();
//temp = null;
//here set 5 seconds, not 60 second I think cancel and restart it
}
答案 0 :(得分:1)
我只是修理它,我在方法onclick上初始化了计时器,它同时有各种计时器!
什么笨拙!
答案 1 :(得分:0)
看不到你的temp.start();也许你应该叫它
编辑reff http://developer.android.com/reference/android/os/CountDownTimer.html
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("done!");
}
}.start();