Home > other >  How to select multiple dates on android calender view
How to select multiple dates on android calender view

Time:05-11

    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?

CodePudding user response:

If you just want to select range of date, try material date picker material date picker doc

 MaterialDatePicker.Builder.dateRangePicker().build().show(supportFragmentManager, "")

CodePudding user response:

            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)

        }
  • Related