英文:
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();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论