How can repeat the event in timer elapsed method in system.timers.timer ??

OmarMohOmarMoh USMember ✭✭
edited August 2016 in Xamarin.Android

Hi guys

My question is I created time picker and also created system.timer and I linked it together to count down the time and displayed in text view , it's work but when the timer done (00:00:00) I want to make event like a massage and restart the same time I choose it from time picker , like when I put 00:02 the timer count down and when time is 00:00 show a massage "timer done" and restart again with the same time 00:02 without stopping, How can I do this ???
here my code

in MainActivity

Timer _timer;
int _countsecond = 1;
TextView textview;
int seconds = 59;
int minutes;
int hours;
Button _btnpick;
Button _start;
OnCreate method
{
textview = FindViewById(Resource.Id.tvTimeCount);
_btnpick = FindViewById(Resource.Id.pickTime);
_start = FindViewById(Resource.Id.startcount);
_start.Click += delegate
{
_timer = new Timer();
_timer.Interval = 1000;
_timer.Elapsed += _timer_Elapsed;
_timer.Enabled = true;
_timer.Start();
};
_btnpick.Click += delegate
{
TimePickerDialog _tp = new TimePickerDialog(this, TimePickerCallback, hours, minutes, true);
_tp.Show();
};

        hours = DateTime.Now.Hour;
        minutes = DateTime.Now.Minute;

}
timer elapsed method
{
CountDownTimer();

        RunOnUiThread(() =>
        {
            UpdateTime();
        });

}
update time method
{
string time;
time = string.Format("{0}:{1}:{2}", hours, minutes, seconds.ToString().PadLeft(2, '0'));
textview.Text = time;
}
CountDownTimer method
{
if (seconds != 0)
{
seconds--;
}
else if (seconds == 0 && minutes != 0)
{
minutes = minutes -= 1;
seconds = 60;
_countsecond--;
}
else if (seconds == 0 && minutes == 0 && hours != 0)
{
hours = hours -= 1;
minutes = 59;
seconds = 60;
_countsecond--;
}
}
Time picker callback method
{
hours = e.HourOfDay;
minutes = e.Minute;
UpdateTime();
}

I tried many ways but was bad , please help me guys

Sign In or Register to comment.