Android : Countdown timer in Android C#

on Tuesday, September 30, 2014


I want to use countdown timer in my Android App using C#


this is the countdown timer class i am using



public delegate void TickEvent(long millisUntilFinished);
public delegate void FinishEvent();

public class CountDown : CountDownTimer
{
public event TickEvent Tick;
public event FinishEvent Finish;

Activity m_owner;
public CountDown(long totaltime, long interval, Activity owner)
: base(totaltime, interval)
{
m_owner = owner;

}

public override void OnTick(long millisUntilFinished)
{
if (Tick != null)
Tick(millisUntilFinished);
long millis = millisUntilFinished;
long hours = millis / (60 * 60 * 1000);
long min = (millis / (60 * 1000)) % 60;
long sec = (millis / 1000) % 60;
TextView txtTime = m_owner.FindViewById<TextView>(Resource.Id.textTime);
txtTime.Text = hours.ToString("00") + ":" + min.ToString("00") + ":" + sec.ToString("00");
}

public override void OnFinish()
{
if (Finish != null)
Finish();
var bulider = new AlertDialog.Builder(m_owner);
bulider.SetMessage("Exam Time Over");
bulider.SetCancelable(false);
bulider.SetPositiveButton("OK", delegate { });
var dialog1 = bulider.Create();
dialog1.Show();

}




}


now i want to call a function from "owner" Activity in timer onFinish(). Is there any way to do so?


Thanks.


0 comments:

Post a Comment