I am trying to show only the current month with the remaining dates selectable in Date Dialog Piker. My Code:
val calendar = Calendar.getInstance()
//getting current day,month and year.
val year = calendar.get(Calendar.YEAR)
val month = calendar.get(Calendar.MONTH)
val day = calendar.get(Calendar.DAY_OF_MONTH)
val datePickerDialog =
DatePickerDialog(
context, DatePickerDialog.OnDateSetListener
{ view, year, monthOfYear, dayOfMonth ->
val currentDate: String = "$year-${(monthOfYear + 1)}-$dayOfMonth"
}, year, month, day
)
// Max = current
val maxTime = calendar.timeInMillis
// Move day as first day of the month
calendar.set(Calendar.MONTH, 1)
// Move "month" for previous one
calendar.add(Calendar.MONTH, 1)
// Min = time after changes
val minTime = calendar.timeInMillis
datePickerDialog.datePicker.maxDate = maxTime
datePickerDialog.datePicker.minDate = System.currentTimeMillis()
datePickerDialog.show()
It's showing the current month and current date selectable but future dates are also disabled. I only want previous dates to be disabled and future remaining dates can be selectable of current month.
You are clearly setting
maxDateminDateto present day so all the other days in calendar was blocked.// above for
maxTimeyou assigned current date don't providemaxDatedatepickerdialogremove above line and check