Date Picker code example for Android Studio

Welcome. Here in this tutorial you will learn how to Date Picker in Android Studio.

Date Picker Example for Android Studio

A date picker is an UI element in android studio that allows you to pick date,month and year. You can make use of calendar and pick date from a calendar style view which is more user-friendly.

For that purpose, we will use the DatePickerDialog and the Calendar class in Android Studio. The code is given below:-

The above code will implement the date picker to pick the date and will display the date as text in the textview named datetext.

An image is shown below which demonstrates a date picker in action:-

The Full Java Code along with the XML layout for the above example is shown below:-

  • First Create a new project in Android Studio
  • File ⇒ New Android ⇒ Application Project
  • Then Open src -> package -> and then add following code :


  •  Now Open res -> layout -> activity_main.xml and then add following code :

XML (activity_main.xml)


Finally, run this project.

This is how Date Picker code example 

Date Picker Example Date Picker Example Date Picker Example

You can directly copy paste these snippets to your android studio, and they should work perfectly. Just save and run your project. You can also try to play with other date picker settings on your own and see the corresponding changes accordingly. There are a variety of properties available which can be changed to make a custom date picker for your android app.

For a more detailed guide, you can also visit android’s official guide below:-

With this we came to an end of our tutorial. Comment down below if you are facing any problems.

Also Read:-

Leave a Reply

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