When to use DatePickerDialog over a DatePicker in a DialogFragment? - android

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.

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 ?
Use DatePicker control in your activity layout (in case you have enough space)
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.

Related

How to extend TimePicker widget?

I want to disable past time numbers in TimePicker. In DatePicker there is a special property for disabling past dates and there is no one for TimePicker so I need to extend an original TimePicker. As I understand I need to change a layout. How to get access to the layout?
Important: android/frameworks/base/core/res/res/layout/time_picker.xml is not an answer - it has got a reference to TimePicker widget where there are no links to other layout files.
Instead of extending a timepicker, extend from dialogfragment and on your onCreateDialog() method return a timepocker dialog. Also remember to implement OnTimeChangedListener so that you can validade the selected date as you need. If you're creating a picker thats gonna be used throughout your whole application you should also consider overriding onDismiss() and then pass the selected date to the activity which started it. Hope this helps

What is the name of the 3 controls used in each picker dialog class?

I can't find the name of the controls used in these dialogs. I'm talking about the 3 up-down sliding selection controls used in each picker dialog.
http://developer.android.com/guide/topics/ui/controls/pickers.html
It's a NumberPicker. You can see the docs here.
DatePicker and TimePicker
DatePicker
http://developer.android.com/reference/android/widget/DatePicker.html
TimePicker
http://developer.android.com/reference/android/widget/TimePicker.html

What User Interface Design or Layout is this

I am currently developing a reservation system application that would require the user to input date and time.
So that would mean that I would have a date picker and a time picker in mu layout file.
Upon doing so, when a user clicks the button to set Date and time of reservation the app will then start an Intent and opens another activity but as far as I see it, It would look awful if I do such so I was wonder how to do this kind of UI so that it would not be as hassle as to start and activity for a result.
You have a number of options to implement this behavior.
The official date picker dialog and time picker dialog.
Given that the use of dialogs is discouraged, try using the widgets inline with CalendarView and DatePicker if you can.
A backported version of the widgets CalendarView and DatePicker.

Android: timepicker and datepicker in the same dialog box

I am developing an app for android. I have created a timepickerdialog and a datepickerdialog, but the problem is, both of them run in different dialog boxes, which is not what the way I want my app to work :-S
Is there any way to create a single dialogbox with both time and date picker dialog boxes in it together?
Thx
You can find a DateTimePicker implementation here:
http://code.google.com/p/datetimepicker/
I have created a custom Alert Dialog as in the Google tutorial. I replaced the ImageView and the TextView with a DatePicker and a TimePicker. I changed the following line:
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
with this:
View layout = inflater.inflate(R.layout.dialog_date_time,
(ViewGroup) findViewById(R.id.datePicker));
For whatever reason the first gave an error, but the second worked. Anyway, I can use the two views in the same dialog window now.
call time picker dialog in datepicker's update time method,It'll not be called at the same time but when you press datepicker's set button,Time picker dialog will open . The method is given in the answer of this link:
DateTime picker in android application

android DatePickerDialog

Is there any way to make DatePickerDialog not dismiss after clicking set button ?
Add an OnClickListener for the dialog button and override onClick.
It would be easier to create your own dialog which uses a DatePicker widget in it. You can find an example of how to use the DatePicker widget in your sdk folder under:
ApiDemos/src/com/example/android/apis/view/DateWidgets1.java
ApiDemos/src/com/example/android/apis/view/DateWidgets2.java
Then you can put whatever buttons and actions you want around the date picker.

Categories

Resources