Android Date Picker Dialog Tutorial

In material design, android provide the material date picker dialog to pick date in the application. It is very useful when come to select a date, its accurate and eliminate the human mistake if they enter by text. Date Picker dialog let the user to pick the date from the calendar with the material design interface. In this tutorial, I will tell you on how to use android date picker dialog to pick date in your android project.

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “DatePickerExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Create a new Class

Right click your project name and create a new class “DatePickerFragment”, after that, copy the source code in the bottom in your class.

Edit activity_main.xml

Open the activity_main.xml layout and modify your layout to the following.

Edit MainActivity.java class

Open your mainactivity class and this activity will show the date picker dialog and you can select any date and display in the activity.

Run Your Project

Finally, you are successfully implement the date picker in your android project, you can now open and run it in your device.

(Android Date Picker Dialog)

Source Code

(Visited 1,069 times, 1 visits today)
Advertisements

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *