2016-10-23 14 views
2

どのようにこのタイマーを停止するには?androidでCountDownTimerを停止する方法

すべてのクエリでタイマーをリセットしますが、続行します。新しいクエリごとに新しいタイマーが追加されます。これを解決するには?

new CountDownTimer(zaman, 1000) {      //geriye sayma 

      public void onTick(long millisUntilFinished) { 

       NumberFormat f = new DecimalFormat("00"); 
       long hour = (millisUntilFinished/3600000) % 24; 
       long min = (millisUntilFinished/60000) % 60; 
       long sec = (millisUntilFinished/1000) % 60; 

       cMeter.setText(f.format(hour) + ":" + f.format(min) + ":" + f.format(sec)); 
      } 

      public void onFinish() { 
       cMeter.setText("00:00:00"); 
      } 
     }.start(); 

答えて

14

あなたは続きを読む変数

CountDownTimer yourCountDownTimer = new CountDownTimer(zaman, 1000) {      //geriye sayma 

     public void onTick(long millisUntilFinished) { 

      NumberFormat f = new DecimalFormat("00"); 
      long hour = (millisUntilFinished/3600000) % 24; 
      long min = (millisUntilFinished/60000) % 60; 
      long sec = (millisUntilFinished/1000) % 60; 

      cMeter.setText(f.format(hour) + ":" + f.format(min) + ":" + f.format(sec)); 
     } 

     public void onFinish() { 
      cMeter.setText("00:00:00"); 
     } 
    }.start(); 

yourCountDownTimer.cancel(); 

としてそれを定義する必要があります:https://developer.android.com/reference/android/os/CountDownTimer.html

+0

this.cancel()または単にcancel()を呼び出すことができますので、多くのyourCountDownTimerありがとう。キャンセル();作品 – Taha

+0

ようこそ。それは私の答えを受け入れるのに役立ちます@ Taha –

+0

yourCountDownTimer.stop()?それは.cancel()でしょうか? –

1

あなたは、そのコールバックメソッドの1

関連する問題