Android date picker dialog


Download android date picker sample

Sometimes, we need to capture date from user. If we forced our users to type required date then there is chance for mis-typing and also selecting a date is quite easy rather than type.

In android, we can use in built datePicker dialog to capture a date from user.

Android date picker dialog Android date picker dialog


Example


Step 1: Create a new project in Android Studio and name it Android date picker.

Step 2: Open res -> drawable and add a xml resource file with a name date_selector.xml. Now, replace the code of date_selector.xml with the below given code.

date_selector.xml

Step 3: Open MainActivity.java and replace its code with below given code.

MainActivity.java

Step 4:Open res -> drawable -> activity_main.xml and replace the code with code of activity_main.xml with the below given code.

activity_main.xml

Step 5:Clean and run your project to see the result.

Share & Like

Tutorial topics

About ApnaTutorials.com

ApnaTutorials.com is for Java, J2ee, Html5 and android developers. All tutorials are well explained and are easy to understand. We have tested every tutorials on our developement environment before posting it in public domain.