4

When should I use say a DatePickerDialog over a DatePicker widget inflated in a DialogFragment? I've always done it the second way and have no idea when/how to use the first method. The same question applies to other picker widgets like TimePicker and TimePickerDialog as well.

Luke Casey
  • 135
  • 1
  • 2
  • 10

1 Answers1

4

Difference between DatePickerDialog and DatePicker

  • DatePicker - It is a Control by itself.

  • DatePickerDialog - It is a dialog with a date picker

When should I use ?

  1. Use DatePicker control in your activity layout (in case you have enough space)
  2. Use the DatePickerDialog when you don't have enough space and/or if you want to open the date dialog in a separate view.

As per the doc, DatePickerDialog is a

A simple dialog containing an DatePicker.

PS. In my experience, I would avoid using it the DatePicker in the activity layout straight away because of space constraints. Consider devices like nexus 4 when you use them.

  • Thanks for the reply, can you explain what you mean by space constraints? Do you mean the size of the device? And why does that play a part in choosing which to use? – Luke Casey Aug 23 '16 at 10:28
  • Yes. That is my personal experience. What I actually meant was, all date pickers require a scroll view when you have other controls in the activity. When you want the users focus on the date picker alone, you might want to use it in a dialog. – Jaswanth Manigundan Aug 24 '16 at 23:22