While setting Minimum date for one year calendar is showing hidden date in the calendar header

61 views Asked by At

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

After switching to previous date without changeing any thing , In the header its showing 2019 sat,sept 28 which was in hidden date in calendar

I have searched for solution but not yet resolved , please help me , Thank you

0

There are 0 answers