I set a minimum date to the DatePicker
(#setMinDate
) and though dates before the minDate are not displayed, there's a bug that if i change the year to past year (with same date as current day), and press OK, the date chosen is a date before the minDate i gave.
This was the code i used
private fun customCalender() {
val cal = Calendar.getInstance()
val cal1 = Calendar.getInstance()
val dialog = DatePickerDialog(this@MainActivity, { arg0, arg1, arg2, arg3 ->
Toast.makeText(this@MainActivity, "" + arg1 + "/" + (arg2 + 1) + "/" + arg3, Toast.LENGTH_SHORT).show()
}, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH))
cal1.add(Calendar.YEAR, -1)
dialog.datePicker.minDate = cal1.timeInMillis
dialog.datePicker.maxDate = System.currentTimeMillis()
dialog.show()
}
Please refer the screen shots for references , While i am selecting a date a day before the maximum date i.e i am selecting 2020 Mon,sept 28 as it showing in header
I have searched for solution but not yet resolved , please help me , Thank you