如何创建无限循环 [英] How to create an infinite loop

查看:83
本文介绍了如何创建无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我需要在倒计时上创建一个无限循环.我的代码是:

Ok,I need to create an infinite loop on a countdown. My code is:

public void countdown() {
    if (x != null) {
        x.cancel();
    }

    x = new CountDownTimer(20000, 1000) {
        public void onTick(long millisUntilFinished) {
        }

        public void onFinish() {
            showNotification();
        }
    };
    x.start();
}

x只是一个静态的countdowntimer变量.问题是我尝试了很多方法来使上述代码正常工作,我的意思是当倒计时结束时,它显示该通知,它应该重新开始,依此类推....但是我找不到办法

x is just a static countdowntimer variable. The problem is that I tried many methods to make the above code work,I mean when the countdown ends,and it displays that notification,it should start again and so on....but I can't find a way to do it.

推荐答案

希望这会对您有所帮助.

Hope this will help you.

public void countdown(){
    if (x != null) {
        x.cancel();
    }
    x = new CountDownTimer(20000, 1000) {
       public void onTick(long millisUntilFinished) {
        }
       public void onFinish() {
           showNotification();
            x.start();
        }
    };
 }

这篇关于如何创建无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆