Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 810
ElTourero Avatar asked May 12 '11 09:05

ElTourero


People also ask

Is DatePicker dialog class available in Android?

Android Date Picker allows you to select the date consisting of day, month and year in your custom user interface. For this functionality android provides DatePicker and DatePickerDialog components.

What is DatePicker and TimePicker in Android?

Android DatePicker is a widget to select date. It allows you to select date by day, month and year. Like DatePicker, android also provides TimePicker to select time. The android.

How do I open an Android calendar?

Get Google Calendar On your Android phone or tablet, visit the Google Calendar page on Google Play. Tap Install. Open the app and sign in with your Google Account.


2 Answers

You can find a DateTimePicker implementation here:

http://code.google.com/p/datetimepicker/

like image 195
BFil Avatar answered Sep 22 '22 16:09

BFil


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.

like image 22
Ovid Avatar answered Sep 26 '22 16:09

Ovid