question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot Programmatically Select Last Date In Range

See original GitHub issue

Disclaimer: I am writing my app in Kotlin

For my app I need the last date in my range to be the current date, and for the current date to be the default selection when the view loads. When I provide the current date as the endDate for the calendar, the calendar selects the first date in the range as the default.

val startDate = Calendar.getInstance()
startDate.add(Calendar.MONTH, -1)

val endDate = Calendar.getInstance()

datePicker = HorizontalCalendar.Builder(activity, R.id.calendarView)
    .range(startDate, endDate)
    .datesNumberOnScreen(7)
    .build()

When the view loads, the calendar has selected the first date in the range. I have also tried adding the following after the above code:

datePicker?.selectDate(Calendar.getInstance(), true) datePicker?.goToday(true)

as well as adding the following to my build chain:

.defaultSelectedDate(Calendar.getInstance())

and none of those did the trick. if I increase the endDate by a single day everything works fine.

I am still able to manually select the final date in the range, everything still works fine with manual selection.

I saw in an old thread there had been issues with the number of dates displayed, and I tried changing that to 5. This also had no effect.

Thanks in advance!

Steps to Reproduce the Problem (sample code if possible)

  1. Initialize a HorizontalCalendar with Calendar.getInstance() as the end date.

Specifications

  • Android Version: 26
  • Horizontal-Calendar Version: 1.3.0

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
benroamancommented, Feb 5, 2018

@Mulham-Raee I upgraded to 1.3.4 and I still have this behavior. The last date (today) is automatically selected when the view loads, but If I select another date and then select the last date (today) again, the ui shows my selection but onDateSelected is not invoked.

Here’s my setup for your reference

        val startDate = Calendar.getInstance()
        startDate.add(Calendar.MONTH, -1)

        val endDate = Calendar.getInstance()

        datePicker = HorizontalCalendar.Builder(activity, R.id.calendarView)
                .range(startDate, endDate)
                .datesNumberOnScreen(7)
                .build()

        datePicker?.calendarListener = object: HorizontalCalendarListener() {
            override fun onDateSelected(date: Calendar?, position: Int) {
                selectDate(date)
            }
        }

Please let me know if there’s any other info you would find helpful.

Thanks!

2reactions
muraeecommented, Jan 3, 2018

Yes this is probably related to the same problem, thanks for pointing it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date range not selected in calendar after value changed ...
I am using BootStrap Datepicker daterange feature. When I set the dates programmatically, the calendars don't display correctly ...
Read more >
Allow selecting same date in DateRangePickerWrapper #914
I have an inline calendar where the date range can span a single day. Is it possible to allow the end date to...
Read more >
Programatically selecting range of data - Qlik Community
Solved: Hey, I am currently working on a project where I require the functionality to programmatically select data from a qlik object.
Read more >
Can I create a dynamic date filter that prompts user to select a ...
“week 52”) programmatically, and then map the user's selection to a date ... Can't you just use the Week End Date field as...
Read more >
Date Range Picker — JavaScript Date & Time Picker Library
singleDatePicker : (true/false) Show only a single calendar to choose one date, instead of a range picker with two calendars. The start and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found