2012-03-03 58 views
0

基本上我的目标是让这个定时器重置,只要用户按下按钮b。我已经尝试了几种方法,如if(i==true && bIsPressed())但没有运气,有什么想法?CountDownTimer问题

//2 buttons 

Button =b; 
TextView = time; 

//countdown code 

    CountDownTimer Count = new CountDownTimer(11000, 1000) { 
    public void onTick(long millisUntilFinished) { 
     time.setText(""+millisUntilFinished/1000); 
    } 

    public void onFinish() { 
     time.setText("Finished"); 
    } 

    }; Count.start(); 

回答

1

没有测试过,但我会做线沿线的东西:

private void setupTimerResetButton() 
{ 
    mTimerResetButton.setOnClickListener(new OnClickListener(){ 
     public void onClick(){ 
      resetTimer(); 
     } 
    }); 
} 

private void resetTimer() 
{ 
    if(mTimer != null){ 
     mTimer.cancel(); 
     mTimer = null; 
    } 
    mTimer = new CountDownTimer(11000, 1000) { 
     public void onTick(long millisUntilFinished) { 
      mTimerTextView.setText(""+millisUntilFinished/1000); 
     } 

     public void onFinish() { 
      mTimerTextView.setText("Finished"); 
     } 
    }; 
    mTimer.start(); 
}