Android: timepicker and datepicker in the same dialog box

23,670

Solution 1

You can find a DateTimePicker implementation here:

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

Solution 2

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.

Share:
23,670
ElTourero
Author by

ElTourero

Updated on July 09, 2022

Comments

  • ElTourero
    ElTourero almost 2 years

    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

  • Vikas Gupta
    Vikas Gupta almost 11 years
    Can't believe that this answer has no upvote and not the accepted one.. +1 because it gave me exactly what I was looking for :)
  • Kishan Vaghela
    Kishan Vaghela over 8 years
    I create project by using this source , make some changes and Migrating to Android Studio github.com/Kishanjvaghela/datetimepicker