Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How can link the timer with timepicker ????

OmarMohOmarMoh USMember ✭✭
edited July 2016 in Xamarin.Android

Hi all

I created a time picker with 24 mode and the time displayed in a text view and I want to create a down counter for the time , when the user select a time and click start button the time should be count down in the text view , some files from my project =>

1 : timepickerfragmentactivity
`public class TimePickerFragment : DialogFragment,
TimePickerDialog.IOnTimeSetListener
{

    // TAG can be any string of your choice.
    public static readonly string TAG = "X:" + typeof(TimePickerFragment).Name.ToUpper();

    // Initialize this value to prevent NullReferenceExceptions.
    Action<string> _dateSelectedHandler = delegate { };


    public static TimePickerFragment NewInstance(Action<string> OnTimeSet)
    {
        TimePickerFragment frag = new TimePickerFragment();
        frag._dateSelectedHandler = OnTimeSet;

        return frag;
    }

    public override Dialog OnCreateDialog(Bundle savedInstanceState)
    {
        DateTime currently = DateTime.Now;
        TimePickerDialog dialog = new TimePickerDialog(Activity, this,
            currently.Hour,
            currently.Minute,
                                                       true);
        return dialog;
    }

    public void OnTimeSet(TimePicker view, int hourOfDay,int minute)
    {
        string time;
            time = string.Format("{0}:{1}", hourOfDay, minute.ToString().PadLeft(2, '0'));
            _dateSelectedHandler(time);
    }
}`

2:MainActivity
``_pick_button = FindViewById(Resource.Id.pickTime);
_pick_button.Click += delegate
{
txt = FindViewById(Resource.Id.txtview);
_time = TimePickerFragment.NewInstance(delegate (string time)
{
txt.Text = time;

             });
            _time.Show(FragmentManager, TimePickerFragment.TAG);
        };

`
I know I have to use a System.Timers; and also I have to invoke Activity.RunOnUiThread(() =>{}); with timer but I don't have the correct way to use this and where can I but the codes ??? please someone help me or give me another way

Sign In or Register to comment.