androidkotlinandroid-calendar

How to select multiple dates on android calender view


    val calendar: Calendar = Calendar.getInstance()
    calendar.set(2022, 5, 10)
    val dateSelected = calendar.timeInMillis

    val calender2 = Calendar.getInstance()
    calender2.set(2022, 5, 11)
    val dateSelected2 = calender2.timeInMillis
    
    binding?.calenderView?.setDate(dateSelected, true, true)
    binding?.calenderView?.setDate(dateSelected2, true, true)

I've tried to select two dates as shown above, but it doesn't work? Any help?


Solution

  •             val dateRangePicker =
                MaterialDatePicker.Builder
                    .dateRangePicker()
                    .setTheme(R.style.ThemeOverlay_MaterialComponents_MaterialCalendar)
                    .setTitleText("Title")
                    .setSelection(
                        Pair(
                            MaterialDatePicker.thisMonthInUtcMilliseconds(),
                            MaterialDatePicker.todayInUtcMilliseconds()
                        )
                    )
                    .build()
    
            dateRangePicker.show(childFragmentManager, "tag")
            dateRangePicker.addOnPositiveButtonClickListener {
                println(it.first)
                println(it.second)
    
            }