Hello I'm having trouble with the countdown timer function
First I want to stop counting it down I'm Counter.cancel (); So I store the unilifiable value in the counter in the countercurrent.
Then I restart the timer using that stored counterwork value. It all works well but when I try to cancel the second time, it can never stop the timer. Just works once, am I forgetting something? Here is my code: Thank you:
// Main code: Mikount counter = new mount (59000, 1000); Counter.start (); // Start timer 59 seconds /// button 1.setOnClickListener (New View.OnClickListener () {public void onClick (see v) {counter.cancel (); // - & gt; Cancel timer works here, Clock closes OK // // Rest of code snipped button2.setOnClickListener (New View.OnClickListener () {public void onClick (see v) {MyCount counter = new MyCount (countcur, 1000); // countcur final counter price When the last canceled is Counter.start (); // This resume timer is okay, when the button 1 is canceled again to cancel it, it does not cancel. Rest of the code Snippet // timer setup public class MyCount countdown timer {public MyCount (long million intervals, long calculation) {super (millise infue, countdowndown interval);} FINISH on public void (intent) = intent (new intent); Intention .Setclass (Main, Final); Start activity (intent);} and {Marekent counters = new mikant (59000, 1000); Counter. Start (); clock = counter.stusting ();}} Public blank Tick at (perpendicular Time to Unilifineted) {// int min = 5; / * If (+ MilliTintly Finish / 1000 & lt; = 240) {min = 4; Mintosec = "240"; // milliseuticalfinished = 59000; } And if (+ miliceaninted / 1000 = lt; = 180) {min = 3; Minotesque = "180"; } And if (+ mile annuity ended / 1000 & lt; = 120) {min = 2; Minotesque = "120"; } And if (+ million unilified 1000 / lt; = 60) min = 1; Minutsake = "60"; * / // textview totmin = (TextView) findViewById (R.id.clockmin); //totmin.setText (""); TextView totsec = (TextView) findViewById (R.id.clocksec); Totsec.setText (+ Duration + ":" + millisUntilFinished / 1000); Cowcur = millisignment; // Stop the current calculation value to stop and restart}} / / and the timer
In the following, you are setting a local variable instead of the class variable:
button2.setOnClickListener (new View.OnClickListener () {public void onClick (see v) {MyCount counter = New MyCount Countcur, 1000); // countcur, if the last cancellation is the current counter value Instead of referencing the current class variable, change it to:
button2. SetOnClickListener (see new OnClickListener) {public void onClick (see v) {counter = new MyCount (countcur, 1000); // countcur is the last counter value when the last cancellation < / Html>
Comments
Post a Comment