0

I have 3 buttons. If I click on a button, I have to disable all the buttons until the countdown timer expires.

I am trying to make a Global countdown timer.

Could you tell how to make it working?

Nicolas Henneaux
  • 11,507
  • 11
  • 57
  • 82

1 Answers1

0

I haven't tried this myself, but some quick searching found a CountDownTimer class in Android that looks like it might work for you.

The example code they give looks pretty straightforward:

new CountDownTimer(30000, 1000) {
    public void onTick(long millisUntilFinished) {
        mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
    }

    public void onFinish() {
        mTextField.setText("done!");
    }
}.start();
Mike
  • 2,132
  • 3
  • 20
  • 33
  • Yes this is right but needed to make this Global for some of the classes.Because they are associated with each other in some way.And I needed to setup these classes according to this timer.For example if I say " A class sending email will not be able to send email untill timer expires" or "A class in the same project will disable all the buttons untill timer expires". A global timer for some of the classes. – Raju Rastogi Feb 16 '15 at 17:28
  • Ah, you need it (potentially) in any activity of your app, not just the same one. In that case, this question might have already addressed it: http://stackoverflow.com/questions/13011939/global-timer-in-android – Mike Feb 16 '15 at 17:31
  • I have seen that but I am unable to understand it.What is singlton class and how to make. – Raju Rastogi Feb 16 '15 at 17:33
  • This is getting beyond the scope of this site, probably (as in, now we're in "google around and learn" territory rather than "ask a question and get an answer" territory), but this answer on another question has some example code. If that's not enough, it might be a good idea to just search for "singleton design pattern" and read a bit about them: http://stackoverflow.com/a/16518088/592351 – Mike Feb 16 '15 at 17:36