Detect listener on month scrolling in android times square

假装没事ソ 提交于 2019-11-28 21:26:25
Samuil Yanovski

Using the CalendarCellDecorator you could write something like this:

public class MonthDecorator implements CalendarCellDecorator {

    @Override
    public void decorate(CalendarCellView calendarCellView, Date date) {
        if (date.getDate() < 5) {
            calendarCellView.setBackgroundResource(R.drawable.red_background);
        } else {
            calendarCellView.setBackgroundResource(R.drawable.blue_background);
        }
    }
}

It is a simple example - the first 5 days in every month will have a different background than the rest of the days. Every cell in every month passes through the decorator, so you could use it to change the UI of cells in multiple months. Generally you'll have to store the dates which should be highlighted CalendarCellDecorator and in the decorate method check whether the given cellView is showing one of these dates. In my case I just check whether the date is before 5th, but you could make a more meaningful check there - i.e. give a range of dates and check whether the given date is inside this range for example.

EDIT: showing how to apply the decorator:

calendar.init(lastYear.toDate(), nextYear.toDate()).inMode(CalendarPickerView.SelectionMode.RANGE);
List<CalendarCellDecorator> decoratorList = new ArrayList<>();
decoratorList.add(new MonthDecorator());
calendar.setDecorators(decoratorList);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!