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)}" textview.setText(dateString) }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)) dpd.show()