0

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();   
         }
     }
SopheakVirak
  • 961
  • 6
  • 14
  • 36
  • 1
    I hope this link will help you : http://w2davids.wordpress.com/simple-countdowntimer-example/ – Mani Nov 17 '13 at 10:15
  • @Manidroid thank you so much but that is not that I need. I just want to Pause timer based on code above. Thank you Manidroid. – SopheakVirak Nov 17 '13 at 10:21

1 Answers1

1

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

Community
  • 1
  • 1
Mithil Jadhav
  • 76
  • 1
  • 5