title: TimePicker with 15 minutes interval in xamarin forms
body: <p>I need to set 15 minutes interval in Time Picker. I have done for iOS. But in Android it is not working.</p>
  <p>For iOS I used following code and it is working:</p>
  <pre><code>public class CustomTimePickerRenderer : TimePickerRenderer
  {
      protected override void OnElementChanged(ElementChangedEventArgs&lt;TimePicker&gt; e)
      {             base.OnElementChanged(e);             var view = (TimePicker)Element; 
          if (view != null)
          {                 var timePicker = (UIDatePicker)Control.InputView;
              timePicker.MinuteInterval = 15;             }
      }
  }
  </code></pre>
  <p>For Andoroid I am trying with following code:</p>
  <pre><code>public class CustomTimePickerRenderer : TimePickerRenderer
  {
      Context _context;
  
      public CustomTimePickerRenderer(Context context) : base(context)
      {
          _context = context;
      }
  
      protected override void OnElementChanged(ElementChangedEventArgs&lt;Xamarin.Forms.TimePicker&gt; e)
      {
          base.OnElementChanged(e);
  
          TimePickerDialogIntervals timePickerDlg = new TimePickerDialogIntervals(this.Context, new EventHandler&lt;TimePickerDialogIntervals.TimeSetEventArgs&gt;(UpdateDuration),
              Element.Time.Hours, Element.Time.Minutes, true);
  
          var control = new EditText(this.Context);
          control.Focusable = false;
          control.FocusableInTouchMode = false;
          control.Clickable = false;
          control.Click += (sender, ea) =&gt; timePickerDlg.Show();
          control.Text = Element.Time.Hours.ToString(&quot;00&quot;) + &quot;:&quot; + Element.Time.Minutes.ToString(&quot;00&quot;);
  
          SetNativeControl(control);
      }
  
      void UpdateDuration(object sender, Android.App.TimePickerDialog.TimeSetEventArgs e)
      {
          Element.Time = new TimeSpan(e.HourOfDay, e.Minute, 0);
          Control.Text = Element.Time.Hours.ToString(&quot;00&quot;) + &quot;:&quot; + Element.Time.Minutes.ToString(&quot;00&quot;);
      }
  }
  
  public class TimePickerDialogIntervals : TimePickerDialog
  {
      public const int TimePickerInterval = 15;
      private bool _ignoreEvent = false;
  
      public TimePickerDialogIntervals(Context context, EventHandler&lt;TimePickerDialog.TimeSetEventArgs&gt; callBack, int hourOfDay, int minute, bool is24HourView)
          : base(context, (sender, e) =&gt; {
              callBack(sender, new TimePickerDialog.TimeSetEventArgs(e.HourOfDay, e.Minute * TimePickerInterval));
          }, hourOfDay, minute / TimePickerInterval, is24HourView)
      {
      }
  
      protected TimePickerDialogIntervals(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
      {
      }
  
      public override void SetView(Android.Views.View view)
      {
          SetupMinutePicker(view);
          base.SetView(view);
      }
  
      void SetupMinutePicker(Android.Views.View view)
      {
          var numberPicker =  FindMinuteNumberPicker(view as ViewGroup);
          if (numberPicker != null)
          {
              numberPicker.MinValue = 0;
              numberPicker.MaxValue = 3;
              numberPicker.SetDisplayedValues(new String[] { &quot;00&quot;, &quot;15&quot;, &quot;30&quot;, &quot;45&quot; });
          }
      }
  
      protected override void OnCreate(Android.OS.Bundle savedInstanceState)
      {
          base.OnCreate(savedInstanceState);
          GetButton((int)DialogButtonType.Negative).Visibility = Android.Views.ViewStates.Gone;
          this.SetCanceledOnTouchOutside(false);
      }
  
      private NumberPicker FindMinuteNumberPicker(ViewGroup viewGroup)
      {
          for (var i = 0; i &lt; 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;
      }
  }
  </code></pre>
  <p>But Android code is not working. I think the issue is with the number picker in SetupMinutePicker method. I am getting null in number picker.
  Please let me know how I can fix this number picker issue or is there any alternate solution to set 15 minutes interval in time picker.</p>