In android development, the time control is an indispensable part, especially when setting personal birthdays or searching by time. Android has built-in DatePicker and timePicker, which are quite convenient to use. You can call findViewById after adding them to the layout, or you can directly rewrite onCreateDialog (int id) in the activity) call the showDialog (int id) method to bring up the showDialog (int id). Currently, the online demo of the android time control is mostly based on the usage instructions of these two controls. However, anyone who has used these two controls knows that these two time selection boxes are not very good: 1. They are not very beautiful. 2. the lifecycle of the time control is uncontrollable. To solve the problem above, we generally write a time control that is beautiful and meets the requirements by inheriting the Dialog. However, this takes much more time than using DatePicker and timePicker. Of course, there are still many good open-source time controls on the Internet for us to choose from, such as android-wheel, it is a time Selection control that imitates the IOS scroll wheel style (people who have used datePicker and timepicker should know that showDialog (int id) is actually an outdated method, this method was deprecated in API level 13.Use the new DialogFragment class with FragmentManager instead; this is also available on older platforms through the Android compatibility package. the showDialog (int id) method is outdated in API 13. The new API can use the DialogFragment class and Instead of FragmentManager, DailogFragment and FragmentManager are also available in version APIs (less than 13), but compatible packages need to be introduced. Next let's take a look at how to use DialogFragment and FragmentManager to select a time, and what advantages does it have over showDialog (int id? First, go to The android developer website, where the official website contains the following sentence: The DialogFragment manages the dialog lifecycle for you and allows you to display the pickers in different layout deployments, such as in a basic dialog on handsets or as an embedded part of the layout on large screens. dialogFragment allows us to manage the time, select the lifecycle of the control, and set different configuration parameters for the control. This allows us to display the control in the basic shape, it can also be placed in a layout and wrapped in a large screen mobile phone. Similarly, the use of DialogFragment on the official website is also very convenient. Next let's take a look: first, we need to customize a Fragement and let it inherit DialogFragment. We also need to make it implement TimePickerDialog. onTimeSetListener interface, the Code is as follows: public class DatePickerFragment extends DialogFragment implements DatePickerDialog. onDateSetListener {int _ year = 1970; int _ month = 0; int _ day = 0; @ Override public Dialog onCreateDialog (Bundle savedInstanceState) {final Calendar c = Calendar. getInstance (); int year = c. get (Calendar. YEAR); int month = c. get (C Alendar. MONTH); int day = c. get (Calendar. DAY_OF_MONTH); return new DatePickerDialog (getActivity (), this, year, month, day) ;}@ Override public void onDateSet (DatePicker view, int year, int monthOfYear, int dayOfMonth) {// when the TODO date is selected, the _ year = year; _ month = monthOfYear + 1; _ day = dayOfMonth; Log. I (Constant. LOG_TAG, "year =" + year + ", monthOfYear =" + monthOfYear + ", dayOfMonth =" + dayOfMonth);} private Str Ing getValue () {return "" + _ year + _ month + _ day;} When we click a control, a time selector will pop up. Just call the following method. Private void showDatePickerFragemnt () {DialogFragment fragment = new DatePickerFragment (); fragment. show (getSupportFragmentManager (), "datePicker ");}