Updated 29 January 2021
In this blog we will read how we can use DatePickerDialog in android . DatePikcerDialog in android allows user to select date . DatePickerDialog allows user to select day,month and year in our application.
activity_main.xml
In xml file we will use a button and a Textview . when user click on button he will see a Dialog and he can select date from that dialog. Which date user select will be visible in text view and you can see complete code for activity_main.
DatePickerDialog select date from instance of Calendar so we use get Instance method. check below code and See how can we get instance of Calendar.
If you want to set date so use OnDateSetListener() interface .check and see below to set date from date picker dialog.
Initialize date picker dialog and send needed parameter .
MainActivity
In MainActivity you can we use a click listener when you click on button it will show a dialog and here you can select date.
You can change background color and button colors. In style you can provide negative button and positive button .
styles.xml
And here you can check screenshot of date Picker how it will show
So here we discussed about how we can use DatePickerDialog in android . Thanks for reading this blog and You can get other blogs from here
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
2 comments
Your welcome