1

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

ADM
  • 20,406
  • 11
  • 52
  • 83
  • On Which android version you are testing . I also faced Some issues with `DatePickerDialog` min max dated on API-21 devices . So this can be specific to OS version too . – ADM Sep 29 '20 at 04:58
  • @ADM mine OS version is API-29, i think this is issue was there in all API version – harini Pasupathy Sep 29 '20 at 05:07
  • Not sure . you can try `MaterialDatePicker` its an enhanced widget with Material UI .you can find some sample easily on it – ADM Feb 26 '21 at 09:41
  • @ADM But MaterialDatePicker have another major problem that OK button was not shown for most of the devices , There was a issue already raised forthis https://github.com/material-components/material-components-android/issues/1346 – harini Pasupathy Feb 27 '21 at 15:12

0 Answers0