K
K
Kirill2018-09-18 17:48:57
Android
Kirill, 2018-09-18 17:48:57

DatePicker how to display the day of the week?

Or what is the best way to write this code?

selectDate.setOnClickListener {
            val currentDate = Calendar.getInstance()
            var year = currentDate.get(Calendar.YEAR)
            var month = currentDate.get(Calendar.MONTH)
            var day = currentDate.get(Calendar.DAY_OF_MONTH)

            val listener = DatePickerDialog.OnDateSetListener {datePicker: DatePicker?, selectedYear: Int, selectedMonth: Int, selectedDay: Int ->


                textView2.text = "$selectedDay/${selectedMonth + 1}/$selectedYear"
            }
            val datePicker = DatePickerDialog(this, listener, year, month, day)
            datePicker.show()
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2018-09-18
@red-barbarian

create extension
next

val datePicker = DatePickerDialog(this).apply{
    updateDate(Calendar.getInstance())
    setOnDateSetListener{_,.....
            textView2.text = ....
    }
}

datePicker.show()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question