2013-03-22 19 views
0

我正在做一個應用程序,將使用CountDownTimer 我想使用1倒計時2次倒計時。 如果時間結束,則立即開始新的時間,以此類推。CounDownTimer如何設置計數2次?

現在我有這樣的事情:

cdt = new CounDownTimer(time,1000) { 
    public void onTick(…) { 
     //code 
    } 
    public void onFinish() { 
     //and here I'm thinking to add a new time, but it doesn't work 
    } 
}; 

如何做到這一點?或者也許還有其他更簡單的選擇來解決這個問題?

感謝您的幫助!

回答

0

您的課程中的某處newMyCountdownTimer(time,interval).start();

private class MyCountdownTimer extends CountDownTimer 
{ 


    public MyCountdownTimer(long millisInFuture, long countDownInterval) 
    { 
     super(millisInFuture, countDownInterval); 
    } 

    @Override 
    public void onFinish() 
    { 
     if (somecondition is satisfied) // be carefull otherwise the countdown keeps running 
     { 
     // newTime and newInterval are variables in the outer class 
      new MyCountdownTimer(newTime, newInterval).start(); 
     } 

    } 

    @Override 
    public void onTick(long millisUntilFinished) 
    { 
     // TODO Auto-generated method stub 

    } 

} 
+0

以及如果我想更改時間(例如10000,而不是5000)?怎麼做? – Ganjira 2013-03-22 23:33:15

+0

我編輯了我的答案。 – 2013-03-22 23:49:45