繁体   English   中英

Android-DialogFragment上的CountDownTimer

[英]Android - CountDownTimer on DialogFragment

因此,我创建了一个创建按钮,将弹出一个警告对话框,其中单选按钮项分别为5分钟,10分钟,15分钟,当我选择该项目时,countdowntimer将基于所选的分钟数开始计时,现在我的问题是如何停止带另一个按钮的计时器。

所以我有2节课:

Start.java

public class Start extends DialogFragments{
CountDownTimer timer1;
//The rest of the code
}

Stop.java

public class Stop extends DialogFragments{
@onCreateDialog
AlertDialog ........
@setPositive.......
// here I want to call the timer to be cancel;
}

我是android环境中的新手,因此我想取消/停止计时器,方法是单击stop片段中的alertdialog中的OK。

在CountDownTimer的活动或片段中保留引用,并使用yourCountDownTimer.cancel()取消引用。

在每个刻度上,您都可以使用惯常的定时更新和享受更新的textview!

 new CountDownTimer(30000, 1000) {

     public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
     }

     public void onFinish() {
         mTextField.setText("done!");
     }
  }.start();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM