Search code examples
c#androiddot42

How to refresh time on android, using dot42 C#


I am new to android-programming, I wanted to make an application, that shows the actual time. But I can't get it refreshed, and the phone's time, and my app's time will be different.

A part of my code:

protected override void OnCreate(Bundle savedInstance)
    {     
        this.SetTitle("Just a clock!");
        base.OnCreate(savedInstance);
        SetContentView(R.Layouts.MainLayout);
        TextView tw = FindViewById<TextView>(R.Ids.textView1);
        //tw.Click += new EventHandler(tw_Click);
        int color = Color.ParseColor("#483D8B");
        tw.SetTextColor(color);
        tw.SetTextSize(60);
        currentHour = DateTime.Now.Hour;
        currentMinute = DateTime.Now.Minute;
        tw.Text = currentHour + ":" + currentMinute;
    }

I'm looking for any working-ideas.

Thank you.


Solution

  • You cannot update the time this way. You need a DigitalClock or AnalogClock on your layout to do this (or TextClock for API 17).