SopheakVirak
SopheakVirak

Reputation: 961

How to Pause CountDownTimer in Android when onClick

I have a timer running for my IQ activity, and I want to Pause that timer when user click on Answer Button.

Bellow is my running timer and I have cancel timer when onlick but it's doesn't work for me:

timer = (TextView) findviewbyid(r.id.time)

new CountDownTimer(30000, 1000) {

 public void onTick(long millisUntilFinished) {
     timer.setText("seconds remaining: " + millisUntilFinished / 1000);
 }

 public void onFinish() {
     mTextField.setText("done!");
 }
 }.start();

 banana.setOnClickListener(new OnClickListener()
    {
       @Override
       public void onClick(View v)
        {
            CountDownTimer.cancel();   
         }
     }

Upvotes: 0

Views: 4009

Answers (1)

Mithil Jadhav
Mithil Jadhav

Reputation: 76

You can create a variable 'total' for total time and just set: total = millisUntilFinished in the onTick method. Check this answer: https://stackoverflow.com/a/6469166/2126403

Upvotes: 1

Related Questions