我已經使用倒數計時器這樣安卓:完成(CountDownTimer的)被調用,即使取消()被調用
新CountDownTimer(15000,15){
public void onTick(long millisUntilFinished) {
long seconds=millisUntilFinished/1000;
long min=millisUntilFinished%100;
timeleft=(int) (seconds*1000+min);
if(millisUntilFinished>=10000)
{
changeText.setTextColor(Color.GREEN);
}
else if(millisUntilFinished>=5000)
{
changeText.setTextColor(Color.MAGENTA);
}
else
{
changeText.setTextColor(Color.RED);
}
changeText.setText(String.format("%02d", seconds)+ "."+String.format("%02d", min)+" sec");
}
public void onFinish() {
timeleft=0;
missed++;
nametext.setTextColor(Color.RED);
nametext.setText("Time Up!");
bottombutton.setVisibility(View.INVISIBLE);
globalflag=13;
changeText.setTextColor(Color.RED);
changeText.setText("0.00 Sec");
Handler myHandler = new Handler();
myHandler.postDelayed(mMyRunnablecif, 3000);
}
}.start();
上的按鈕點擊我已經調用了cancel(),但它停止計數一段時間,然後調用onFinish()。我不需要在調用cancel()之後調用onFinish()是否有任何解決方案。任何幫助將不勝感激。
不onFinish( )回顧它所屬的活力?或者調用oncreate() – Moyeen
onFinish()關於倒數計時器未連接到活動。這只是倒數計時器完成時調用的方法。 – Tony