thellmund / Android-Week-View

Display highly customizable calendar views in your Android app
Apache License 2.0
188 stars 98 forks source link

How to get current month displayed on weekView with setDateFormatter{} #264

Closed antoniokranjcina closed 3 years ago

antoniokranjcina commented 3 years ago

Hi,

I know that I can use setDateFormatter to get current month displayed in textView. The problem is that if I scroll forward textView is getting updated as it should but when I scroll backward, nothing happens and textView is not getting updated. How to get current month displayed in week view?

setDateFormatter {
    val monthName = SimpleDateFormat("LLLL", Locale.getDefault()).format(it.time)
    val month = monthName.substring(0, 1).uppercase() + monthName.substring(1).lowercase()
    textViewCurrentMonth.text = month

    val dateFormat = SimpleDateFormat("EEE\ndd", Locale.getDefault())
    return@setDateFormatter dateFormat.format(it.time)
}
thellmund commented 3 years ago

Hi 👋 setDateFormatter() is only called the first time that a date needs to be formatted. The result is cached, so it isn’t called again when the user scrolls past this date.

For your use case, you should override onRangeChanged(firstVisibleDate: Calendar, lastVisibleDate: Calendar) in your adapter instead. It’s called whenever the user scrolls to a new date range.