Android Date Picker Examples

DatePicker and DatePickerDialog are often used when requesting user to select date instead of typing in

Show DatePickerDialog in fragment

This will display a DatePickerDialog for user to choose date then output the result to textview.

val c = Calendar.getInstance()
val dpd = DatePickerDialog(activity!!, DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
            val dateString = "$year-${String.format("%02d", monthOfYear+1)}-${String.format("%02d", dayOfMonth)}"
        }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH))

Leave a Comment

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

Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.