Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Android.App;
- using Android.OS;
- using Android.Support.V7.App;
- using Android.Runtime;
- using Android.Widget;
- using System.Threading.Tasks;
- using System;
- namespace digitalClock
- {
- [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
- public class MainActivity : AppCompatActivity
- {
- Task _timer;
- TextView nowTimeLabel;
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
- // Set our view from the "main" layout resource
- SetContentView(Resource.Layout.activity_main);
- nowTimeLabel = FindViewById<TextView>(Resource.Id.nowTimeLabel);
- _timer = new Task(async () =>
- {
- while(true)
- {
- RunOnUiThread(() =>
- {
- nowTimeLabel.Text = DateTime.Now.ToString("HH:mm:ss");
- });
- await Task.Delay(1000);
- }
- });
- _timer.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement