等待倒计时计时器完成

huangapple 未分类评论44阅读模式
英文:

Waiting for a countdowntimer to finish

问题

我需要帮助编写代码,

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

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

  1. ---代码部分1---
  2. While(running){}
  3. ---代码部分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:

  1. ---part 1 of code---
  2. While(running){}
  3. ---part2 of the code---

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

答案1

得分: 1

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

  1. countDownTimer = new CountDownTimer(10000, 1000) {
  2. @Override
  3. public void onTick(long l) {
  4. }
  5. @Override
  6. public void onFinish() {
  7. // 在计时器结束后执行的部分
  8. }
  9. }.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

  1. countDownTimer = new CountDownTimer(10000, 1000) {
  2. @Override
  3. public void onTick(long l) {
  4. }
  5. @Override
  6. public void onFinish() {
  7. //this part will work after timer have finished
  8. }
  9. }.start();

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

发表评论

匿名网友

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

确定