Here is a result of this tutorial:
This project is developed in Eclipse 4.2.0.
1. Make application interface:
The main layout of this app demo is very simple layout. It have one edit test, one button. When user touch on the button the DateTimePicket will show for choose the date and time, the result will be show on edit text. Here is some xml code to make main layout:
To show the custom picker shown in picture above i created a dialog contains three buttons and a new custom view DateTimePicker. The xml file design for dialog is shown here:
Finally, we need to create an interface for new DateTimePicker view. It simply has only some button and edit text. Here is all following xml codes to do that. Of course, you can make it better than me.
2. Time for java code:
The following code below implement when click on the button in main screen.
All we do in this function is create a new dialog, Inflate the root layout for that dialog then set OnClick Listener for three button in interface of dialog, finally we show diallog to the screen. When user click on one of three button, we must execute some task associate with each button. Exactly, cancel the dialog when the "Cancel" button is clicked, Reset Date and Time pickers when the "Reset" button is clicked and Update demo edittext when the "OK" button is clicked.
The most important thing is we declare a DateTimePicker object mDateTimePicker and use many methods are defined in the java class file like reset(), getDay(), getMonth() etc. The source code of DateTimePicker class available here.
3.1. Run application
3.2. After click on the Choose button
3.3. click "OK" button on DateTimePicker Dialog
PS: May be i make a lot of English grammar mistakes when create this tutorial cause my low level of English. Sorry about that.