0

I am making timer and I want to repeat it, for example, 6 times, but I don't know how to set delay and how to each time display me the countdown again on tv1. My code look like that. As you can see in code, I am using Handler method, but I don't know know if it's correct.

tv1=findViewById(R.id.textView);
btn1=findViewById(R.id.button);
final int x=10000;

btn1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        timr =new CountDownTimer(x,1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                tv1.setText(""+millisUntilFinished/1000);
            }

            @Override
            public void onFinish() {
                  new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        
                    }
                })
            }
        }.start();
    }
});
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Joshua
  • 13
  • 5
  • There's no Handler in this code. Could you add the relevant section of the code? – Ryan M Jun 14 '20 at 09:39
  • Sorry I paste wrong code ;/. I edited my question – Joshua Jun 14 '20 at 09:41
  • That's not valid Java. It's missing at least one semicolon, and `postDelayed` has two parameters, not one. – Ryan M Jun 14 '20 at 09:42
  • So what I should to do? – Joshua Jun 14 '20 at 09:46
  • Does this answer your question? [How to call a method after a delay in Android](https://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay-in-android) – Ryan M Jun 14 '20 at 09:48
  • for what do you need the Handler? You already have the tick happening almost every second. You won't manage to get it exactly every second. And the two methods `onTick` and `onFinish` are called on the main thread. So I don't see why you need the Handler – kingston Jun 14 '20 at 10:01
  • if im not wrong, you want to repeat your timer but give it start delay after a timer is finished? – Erwin Kurniawan A Jun 14 '20 at 10:10

1 Answers1

1

In onFinish method add this code

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        timr.start()
    } 
},your_delay)
Rasul
  • 727
  • 7
  • 20