因為我是 android 開發(fā)的新手,所以我需要一些幫助。我正在開發(fā)測驗應用程序,所以我有分數(shù)倒計時。我無法弄清楚如何停止計時器并在自定義對話框中顯示。因此,如果每個問題都將完成,則應停止計時器,并且必須在最后一次對話中。在我將它存儲到數(shù)據(jù)庫中以按時間和分數(shù)對其進行排序之后。這里是倒計時方法。private void countD(){ countDownTimer = new CountDownTimer(timeleftinmilliseconds, 1000) { @Override public void onTick(long l) { timeleftinmilliseconds = l; int minutes = (int) (timeleftinmilliseconds/1000)/60; int second = (int) (timeleftinmilliseconds/1000)%60; String timeletfFormated = String.format(Locale.getDefault(), "%02d:%02d", minutes, second); timetext.setText(timeletfFormated); } @Override public void onFinish() { timetext.setText("00:00"); } }.start();自定義對話框的xml<TextView android:id="@+id/dialog_time_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Your Time is: " android:layout_below="@id/dialog_message" android:textSize="18dp" android:layout_marginTop="20dp" /><TextView android:id="@+id/dialog_time_score" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/dialog_message" android:paddingLeft="10dp" android:text="00:00" android:textSize="18dp" android:layout_marginTop="20dp" android:layout_below="@+id/dialog_score" /><EditText android:id="@+id/edittext_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Please enter your name" android:layout_below="@+id/dialog_time_message" android:layout_marginTop="10dp" />
2 回答

牛魔王的故事
TA貢獻1830條經(jīng)驗 獲得超3個贊
您可以使用 cancel() 方法:
private CountDownTimer countDownTimer;
public void startCount(){
countDownTimer = new CountDownTimer(SECONDS_TO_DISMISS, 1000) {
@Override
public void onTick(long time) {
strong text
**strong text**
}
@Override
public void onFinish() {
}
}.start();
}
public void stopCount(){
countDownTimer.cancel();
}
添加回答
舉報
0/150
提交
取消