Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date and time picker dialog

I want to create a dialog which can select the time and the date at the same time.
I know that there is not a default widget that can do that on Android. I also know that there are open source projects on how do similar staff. The problem in this project is that in the dialog we have two buttons: datePicker and timePicker.

enter image description here

And that's not what I want to do - I want that the date and time picker appear at the same time.
So I think the two main problem will be:

  1. First make the time and date picker appear in the same dialog.
  2. And the second problem will be to change the appearance of time and date picker (the orange color).

The first problem was resolved by Bhavesh. Here is what I get:

enter image description here

The problem now is that I want to change all blue bar color to orange color.
I added android:calendarViewShown="false" to remove the calendar in the right :) Thanks Bhavesh and I changed the theme to HOLO
Here is what I get:

enter image description here

You can download the code (that's the best I can do). You can download from here.

like image 954
haythem souissi Avatar asked Jan 10 '13 09:01

haythem souissi


People also ask

What is date picker dialog?

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 time and date picker in Android?

Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or date (month, day, year).

How do I add date and time picker?

If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C. Under Insert controls, click Date Picker. In the Date Picker Binding dialog box, select the field in which you want to store the date picker data, and then click OK.


1 Answers

First make the time and date picker appear in the same dialog

Here i can help you some what: you can create a layout consisting of a DatePicker and a TimePicker in a LinearLayout with the orientation set to vertical.

custom_dialog.xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >      <DatePicker          android:id="@+id/datePicker1"          android:layout_width="wrap_content"          android:layout_height="wrap_content" >     </DatePicker>      <TimePicker         android:id="@+id/timePicker1"         android:layout_width="wrap_content"         android:layout_height="wrap_content" >     </TimePicker>  </LinearLayout> 

Then use this layout to create your dialog.

Dialog dialog = new Dialog(mContext);  dialog.setContentView(R.layout.custom_dialog); dialog.setTitle("Custom Dialog"); 

To react to the user interacting with your TimePicker, do something like this:

TimePicker tp = (TimePicker)dialog.findViewById(R.id.timepicker1); tp.setOnTimeChangedListener(myOnTimechangedListener); 

To get the values from the Date- and TimePicker when the user has finished setting them, add an OK button in your dialog, and then read the date and time values from the Date- and TimePicker when the user presses OK.

To make something that looks exactly as in your screen shots I recommend you to make all things custom with your own logic.

like image 110
Bhavesh Patadiya Avatar answered Sep 18 '22 11:09

Bhavesh Patadiya