等待倒计时计时器完成

huangapple go评论79阅读模式
英文:

Waiting for a countdowntimer to finish

问题

我需要帮助编写代码,

如何编写代码以等待倒计时计时器结束?

我尝试过使用布尔值来判断倒计时计时器是否在运行,在代码中是这样的:

---代码部分1---

While(running){}

---代码部分2---

这会导致屏幕冻结... 不知道如何解决这个问题.. 有人可以帮忙吗?

英文:

I need help with writing a code,

How do I make a code to wait until the countdown timer is finished?

I tried with boolean says if countdown timer is running and in the code, it was like this:

---part 1 of code---

While(running){}

---part2 of the code---

It makes the screen freeze... Idk how to solve this.. help someone?

答案1

得分: 1

CountDownTimer已经具备这个功能,您只需要将希望在计时器结束后执行的代码放在onFinish()方法内部,就像下面这样:

countDownTimer = new CountDownTimer(10000, 1000) {
    @Override
    public void onTick(long l) {
        
    }

    @Override
    public void onFinish() {
        // 在计时器结束后执行的部分
    }
}.start();
英文:

CountDownTimer already has that, You just need to put the codes that you want to make them work after the timer finished, inside the onFinish(), like below

 countDownTimer = new CountDownTimer(10000, 1000) {
        @Override
        public void onTick(long l) {
        
        }

        @Override
        public void onFinish() {
          //this part will work after timer have finished
        }
    }.start();

huangapple
  • 本文由 发表于 2020年4月6日 00:01:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/61045407.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定