How to use DatePickerDialog in Kotlin?

It would look something like this:

val c = Calendar.getInstance()
val year = c.get(Calendar.YEAR)
val month = c.get(Calendar.MONTH)
val day = c.get(Calendar.DAY_OF_MONTH)


val dpd = DatePickerDialog(activity, DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->

    // Display Selected date in textbox
    lblDate.setText("" + dayOfMonth + " " + MONTHS[monthOfYear] + ", " + year)

}, year, month, day)

dpd.show()

this was done by simply copying and pasting the code into a kotlin file in android studio. I would strongly recommend using it.

Leave a Comment