Android Date Picker Example

In this tutorial you will get android date picker example.

DatePickerDialog is used to show a dialog to pick a date. To show a DatePickerDialog call showDialog() with unique DatePickerDialog id.

onCreateDialog() method is automatically called on calling showDialog() method.

Register OnDateSetListener with DatePickerDialog and override onDateSet() method.

onDateSet() contains the picked date. I am setting the picked date in textview using displayDate() method.

Calendar class is used to get current date.

 

Android Date Picker Example

Create a new android studio project with package name com.datepickerexample.

Create a layout file inside res/layout folder and add following code inside it.

activity_main.xml

 

Create a java source file inside package and add following code.

MainActivity.java

 

Screenshots

Android Date Picker Example

Android Date Picker Example

Comment below if you are facing any problem in above android date picker example.

3 thoughts on “Android Date Picker Example”

  1. Hi.your articles are very helpful.I would like to know how to make a javascript function to show date when a button is clicked.The same function hides the date after the second click.I will appreciate your assistance.Thank you

Leave a Comment

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