Created
July 29, 2015 15:06
-
-
Save mikeedwards83/19cf55bd2208323d8698 to your computer and use it in GitHub Desktop.
Xamarin Countdown Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Simple : CountDownTimer | |
| { | |
| event TickHandler _onTick; | |
| event TickHandler _onFinished; | |
| public event TickHandler OnTicked | |
| { | |
| add { _onTick += value; } | |
| remove { _onTick -= value; } | |
| } | |
| public event TickHandler OnFinished | |
| { | |
| add { _onFinished += value; } | |
| remove { _onFinished -= value; } | |
| } | |
| public delegate void TickHandler(object sender, TickEventArgs args); | |
| public Simple(long totalTime, long interval):base(totalTime, interval) | |
| { | |
| } | |
| public override void OnFinish() | |
| { | |
| if (_onFinished != null) | |
| { | |
| _onFinished(this, new TickEventArgs() { TimeRemaining = 0 }); | |
| } | |
| } | |
| public override void OnTick(long millisUntilFinished) { | |
| if (_onTick != null) | |
| { | |
| _onTick(this, new TickEventArgs() { TimeRemaining = millisUntilFinished }); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Activity(Label = "TimerActivity")] | |
| public class TimerActivity : Activity | |
| { | |
| static int _totalTime = 1000 * 10; // 1000 * 60 * 25; | |
| static int _interval = 1000 * 1; | |
| protected override void OnCreate(Bundle bundle) | |
| { | |
| base.OnCreate(bundle); | |
| SetContentView(Resource.Layout.Timer); | |
| var textView1 = FindViewById<TextView>(Resource.Id.textView1); | |
| var timer = new Simple(_totalTime, _interval); | |
| textView1.Text = "Started"; | |
| timer.OnTicked += (sender, args) => | |
| { | |
| RunOnUiThread(() => | |
| { | |
| textView1.Text = args.TimeRemaining.ToString(); //args.TimeRemaining.ToString(); | |
| }); | |
| }; | |
| timer.OnFinished += (sender, args) => | |
| { | |
| RunOnUiThread(() => | |
| { | |
| textView1.Text = "Finished"; //args.TimeRemaining.ToString(); | |
| }); | |
| }; | |
| timer.Start(); | |
| // Create your application here | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment