Date and Time Dialog Box

I want to create a dialog box in which you can select the time and date at the same time .
I know that there is no default widget that can be done on Android . I also know that there are open source projects on how similar employees work. The problem with this project is that there are two buttons in the dialog box: datePicker and timePicker.

enter image description here

And this is not what I want to do - I want the date and time to be selected at the same time.
Therefore, I think there are two main problems:

  • First make a choice of time and date in the same dialog box.
  • And the second problem will be to change the appearance of the choice of date and time (orange).

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

enter image description here

Now the problem is that I want to change the whole color of the blue stroke to orange.
I added android:calendarViewShown="false" to delete the calendar on 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 (what can I do better). You can download from here .

+51
android datepicker datetimepicker timepicker
Jan 10 '13 at 9:01
source share
3 answers

First make a choice of time and date in the same dialog box

Here I can help you with something: you can create a layout consisting of DatePicker and TimePicker in 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 a dialog.

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

To respond to the user interacting with your TimePicker , follow these steps:

 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 configuring them, add the OK button to your dialog, and then read the date and time values ​​from the Date- and TimePicker when the user clicks OK.

To do something that looks exactly the same as in your screenshots, I recommend that you do whatever you want with your own logic.

+76
Jan 10 '13 at 9:17
source share

To change the color of blue try below.

Define your own theme as follows, which extends THEME_HOLO_DARK

Try the following: -

 <style name="testo" parent="@android:style/Widget.DeviceDefault.DatePicker"> <item name="android:divider">@drawable/MyDivider</item> </style> 

Check out the following change-basic-theme-color-of-android-application

+1
Jan 10 '13 at 9:56
source share

There are many solutions available, there is one of them, I like this simple method:

 String mDateTime; void getDateTime(){ final Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); final int hour = c.get(Calendar.HOUR_OF_DAY); final int minute = c.get(Calendar.MINUTE); mDateTime = ""; new DatePickerDialog( mContext, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { mDateTime = year +"-"+ month +"-"+ dayOfMonth; new Handler().postDelayed(new Runnable() { @Override public void run() { new TimePickerDialog(mContext, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { mDateTime+=" "+hourOfDay+":"+minute; } }, hour, minute, false).show(); } },500); } }, year, month, day).show(); } 
-one
Jul 13 '17 at 12:09 on
source share



All Articles