prolificinteractive / material-calendarview

A Material design back port of Android's CalendarView
https://prolificinteractive.github.io/material-calendarview/
MIT License
5.91k stars 1.32k forks source link

Can I add labels on dates? #1131

Open ruNNiNg-V0V opened 1 year ago

ruNNiNg-V0V commented 1 year ago

I tried add the text to dates with JsonObject, but the text is empty.

class EventDecorator(jsonTotal: JSONObject, dates: HashSet<String>) : DayViewDecorator {
    val totalData = jsonTotal
    val dates: HashSet<String> = dates
    var dDay = ""
    var label = ""
    override fun shouldDecorate(day: CalendarDay): Boolean {
        dDay = getDay(day.year, day.month, day.day)
        label = totalData.getString(dDay)
        return dates.contains(dDay)
    }

    override fun decorate(view: DayViewFacade) {
        view.addSpan(DotSpan(5f, Color.RED))
        // view.addSpan(AddTextToDates(label))
    }

    fun getDay(year: Int, month: Int, day: Int): String {
        val dDay = "$year-" + String.format(
            "%02d",
            month + 1
        ) + "-" + String.format("%02d", day)
        return dDay
    }
}
windcloudit commented 1 year ago

I think you can use this guide to do it, but I don't know how to increase height of row to display this text. Maybe it will be overlap. https://stackoverflow.com/questions/61008523/add-text-to-dates-in-material-calendarview