Kotlin - Display Date picker dialog using EditText

Here is how you can display a date picker dialog using Kotlin in Android.

Result


Code
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 datePicker = DatePickerDialog(this, DatePickerDialog.OnDateSetListener { 
                                         view, year, monthOfYear, dayOfMonth ->    // Display Selected date in textbox    edittext_user_appointment_date.setText("" + dayOfMonth + ", " + monthOfYear +  
                                           ", " + year)
}, year, month, day)

datePicker.show()

Comments

Popular posts from this blog

How to write to a file in Kotlin

Python Tkinter example