Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Xamarin.Forms TimePicker with 15 minutes Intervals?

$
0
0

Hi!
is there a way to get a TimePicker in Xamarin.forms which has only 0,15,30,45 minutes to choose?

I tried using custom renderer in Android with something like this:

`class MyTimePickerRenderer : TimePickerRenderer
{

   protected override void OnModelChanged(Xamarin.Forms.VisualElement oldModel, Xamarin.Forms.VisualElement newModel)
   {
        base.OnModelChanged(oldModel, newModel);          

        Android.Widget.TimePicker tpdi =  (Android.Widget.TimePicker)Control;

        var numberPicker = FindMinuteNumberPicker(tpdi as ViewGroup);
        if (numberPicker != null)
        {
            numberPicker.MinValue = 0;
            numberPicker.MaxValue = 5;
            numberPicker.SetDisplayedValues(new String[] { "00", "15", "30", "45" });
        }


    }
    public NumberPicker FindMinuteNumberPicker(ViewGroup viewGroup)
    {
        for (var i = 0; i < viewGroup.ChildCount; i++)
        {
            var child = viewGroup.GetChildAt(i);
            var numberPicker = child as NumberPicker;
            if (numberPicker != null)
            {
                if (numberPicker.MaxValue == 59)
                {
                    return numberPicker;
                }
            }


            var childViewGroup = child as ViewGroup;
            if (childViewGroup != null)
            {
                var childResult = FindMinuteNumberPicker(childViewGroup);
                if (childResult != null)
                    return childResult;
            }
        }

        return null;
    }
}`

bust it didn't work...

hope you have any ideas ...

FloKo


Viewing all articles
Browse latest Browse all 58056

Trending Articles