Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 倒计时计时器是如何工作的?同样是三次?_Java_C#_Android - Fatal编程技术网

Java 倒计时计时器是如何工作的?同样是三次?

Java 倒计时计时器是如何工作的?同样是三次?,java,c#,android,Java,C#,Android,我有如下所示的代码块。举个例子,我能把这个代码用三次吗 当我使用for循环或其他循环时。这不是我想要的过程 new CountDownTimer(3000,1000) { @Override public void onTick(long l) { gostertext.setText(""+l/1000); durumgoster.setText(

我有如下所示的代码块。举个例子,我能把这个代码用三次吗

当我使用for循环或其他循环时。这不是我想要的过程

new CountDownTimer(3000,1000) {
                @Override
                public void onTick(long l) {


                    gostertext.setText(""+l/1000);
                    durumgoster.setText("KOŞ..");
                }

                @Override
                public void onFinish() {
                    gostertext.setText("KOŞU bitti YÜRÜ");
                    CountDownTimer counter=new CountDownTimer(3000,1000) {
                        @Override
                        public void onTick(long l) {
                            gostertext.setText(""+l/1000);
                            durumgoster.setText("YÜRÜ..");
                        }

                        @Override
                        public void onFinish() {
                            gostertext.setText("bitti");
                        }
                    }.start();
                }
            }.start();
当一个计数器结束时,另一个计数器将开始执行三次。 我编写了代码,如上图所示,这是可行的,但我想执行三次。
我们能解决这个问题吗?

为什么不将循环内容设为1个空,
并调用它三次?

您可以执行以下操作(未经测试):

int countcountcounter=0;
CountdowntTimer MCountdowntTimer=新的CountdowntTimer(){
@凌驾
公共void onTick(长毫秒未完成){
}
@凌驾
公共无效onFinish(){
如果(计数计数器<3){
countcountcounter++;
//取消计数器并重新启动它!
mCountDownTimer.cancel();
mCountDownTimer.start();
}
}
};

请不要标记垃圾邮件。
int countCounter = 0;
CountDownTimer mCountDownTimer = new CountDownTimer() {
    @Override
    public void onTick(long millisUntilFinished) {

    }

    @Override
    public void onFinish() {
        if (countCounter < 3){
            countCounter++;
            // cancel the counter and restart it!
            mCountDownTimer.cancel();
            mCountDownTimer.start();
        }
    }
};