2013-12-19 50 views
0

在我的應用我有一個timer.i後暫停計時器想獲得自身暫停定時器60後secs.can任何一個可以幫助我out..this是我做了什麼如何在固定的時間

private Runnable updateTimerThread = new Runnable() { 

    public void run() { 

     timeInMilliseconds = SystemClock.uptimeMillis() - startTime; 

     updatedTime = timeSwapBuff + timeInMilliseconds; 

     int secs = (int) (updatedTime/1000); 
     mins = secs/60; 

     secs = secs % 60; 
     int milliseconds = (int) (updatedTime % 1000); 
     /*timerValue.setText("" + mins + ":" 
       + String.format("%02d", secs) + ":" 
       + String.format("%03d", milliseconds));*/ 

     timerValue.setText("" + mins + ":" 
       + String.format("%02d", secs)); 
     customHandler.postDelayed(this, 0); 



    } 

}; 
+0

你需要停下來記住舊值,並重新與舊值再次運行當需要時 – Raghunandan

+0

你不能暫停計時器,而是@Raghunandan說 – Hardik

回答

0

btn.setOnClickListener(新View.OnClickListener(){

 @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      startCountDownTimer(); 


     } 
    }); 

保護無效startCountDownTimer(){

  cdTimer = new CountDownTimer(total, 1000) { 
       public void onTick(long millisUntilFinished) { 
        //update total with the remaining time left 
        total = millisUntilFinished; 
        tv.setText("seconds remaining: " + millisUntilFinished/ 1000); 
       } 
       public void onFinish() { 
        tv.setText("done!"); 
       } 
      }.start(); 
    } 
相關問題