Skip to content Skip to sidebar Skip to footer

How Can I Set The Specific Selected Date To Min Date In Android Date Picker?

I have 2 DatePickers, one is start date picker and the other is end date picker. I want to set the min date of the end DatePicker to the start date which user has selected. I've tr

Solution 1:

Note:: TextView hold the reference of text where you want to set the date

private fun openDobPicker(textView: TextView) {
            val c = Calendar.getInstance()
            val year = c.get(Calendar.YEAR)
            val month = c.get(Calendar.MONTH)
            val day = c.get(Calendar.DAY_OF_MONTH)
    
            val dpd = DatePickerDialog(requireActivity(), DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
                val date = "${dayOfMonth}/${monthOfYear}/${year}"
                textView.text = date
            }, year, month, day)
    
            //restrict calendar to show future dates
            dpd.datePicker.maxDate = Date().time
            
            //limit the minimum date then do this
            dpd.datePicker.minDate = PASSED_MIN_DATE_HERE
        
    
            
            dpd.show()
        }

Post a Comment for "How Can I Set The Specific Selected Date To Min Date In Android Date Picker?"