protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button btnStart = FindViewById<Button> (Resource.Id.btnStart); Button btnStop = FindViewById<Button> (Resource.Id.btnStop); Button btnReset = FindViewById<Button> (Resource.Id.btnReset); TextView lblDisplay = FindViewById<TextView> (Resource.Id.lblDisplay); btnStart.Enabled = true; btnStop.Enabled = false; btnStart.Click += delegate { btnStart.Enabled = false; btnStop.Enabled = true; timer.Start(); }; btnStop.Click += delegate { btnStart.Enabled = true; btnStop.Enabled = false; timer.Stop(); lblDisplay.Text = MyTimerLogic.GetCurrentTickCount(); }; btnReset.Click += delegate { MyTimerLogic.SetTickElapsed(); lblDisplay.Text = MyTimerLogic.GetCurrentTickCount(); }; timer.Elapsed += delegate { MyTimerLogic.SetTickElapsed(); RunOnUiThread(delegate { lblDisplay.Text = MyTimerLogic.GetCurrentTickCount(); }); } }; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. btnStart.TouchUpInside += delegate { timer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromSeconds(1), timer_tick); btnStart.Enabled = false; btnStop.Enabled = true; }; btnStop.TouchUpInside += delegate { timer.Invalidate(); btnStart.Enabled = true; btnStop.Enabled = false; }; btnReset.TouchUpInside += delegate { MyTimer.Reset(); lblDisplay.Text = MyTimer.GetCurrentTickCount(); }; }
public void timer_tick() { //Do stuff here MyTimerLogic.SetTickElapsed(); lblDisplay.Text = MyTimerLogic.GetCurrentTickCount(); }