I have one DatePickerDialog
that show after click editText
. That works well. I need to add this code that detect when user click cancel button
after show Dialog
then I will set editText
border according this click. I generally foud java
code in here. I can't use them for mine. How I detect it with my Kotlin
code.
class ManuelBPEnterFragment : BaseFragment<FragmentBpInfoManuelEnterBinding>(
FragmentBpInfoManuelEnterBinding::inflate
) {
private fun showDatePickerDialog() {
DatePickerDialog(
requireContext(),
R.style.DatePickerTheme,
datePicker,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH),
).apply {
datePicker.minDate = System.currentTimeMillis() - 1000
}.show()
}
private val datePicker = DatePickerDialog.OnDateSetListener { _, year, month, dayOfMonth ->
calendar.set(year, month, dayOfMonth)
binding.edtDate.setText(formatter.format(calendar.timeInMillis))
}
}
I tried onClick(DialogInterface.BUTTON_NEGATIVE, which: Int)
inside when show Dialog. I can't write this code block truthly:
DatePickerDialog(
requireContext(),
R.style.DatePickerTheme,
datePicker,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH),
).onClick(DialogInterface.BUTTON_NEGATIVE, which: Int).apply {
datePicker.minDate = System.currentTimeMillis() - 1000
}.show()