Advertisement
Guest User

MainActivity.cs

a guest
Dec 2nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using Android.App;
  2. using Android.OS;
  3. using Android.Support.V7.App;
  4. using Android.Runtime;
  5. using Android.Widget;
  6. using System.Threading.Tasks;
  7. using System;
  8.  
  9. namespace digitalClock
  10. {
  11.     [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
  12.     public class MainActivity : AppCompatActivity
  13.     {
  14.         Task _timer;
  15.         TextView nowTimeLabel;
  16.  
  17.         protected override void OnCreate(Bundle savedInstanceState)
  18.         {
  19.             base.OnCreate(savedInstanceState);
  20.             // Set our view from the "main" layout resource
  21.             SetContentView(Resource.Layout.activity_main);
  22.  
  23.             nowTimeLabel = FindViewById<TextView>(Resource.Id.nowTimeLabel);
  24.  
  25.             _timer = new Task(async () =>
  26.             {
  27.                 while(true)
  28.                 {
  29.                     RunOnUiThread(() =>
  30.                     {
  31.                         nowTimeLabel.Text = DateTime.Now.ToString("HH:mm:ss");
  32.                     });
  33.                     await Task.Delay(1000);
  34.                 }
  35.             });
  36.  
  37.             _timer.Start();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement