마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

material calendarview setTitleFormatter() 질문입니다

0 추천

안녕하세요 안드로이드 초보자입니다

material calendarview를 사용하려는데 캘린더제목이 4월 2020년형식이라 

setTitleFormatter()를 이용해서 2020년 4월로 바꾸고싶은데요 

 

final Calendar date  = Calendar.getInstance();

calendar_view.setTitleFormatter(new TitleFormatter() {
    @Override
    public CharSequence format(CalendarDay day) {
        SimpleDateFormat calendar_view_format = new SimpleDateFormat("yyyy MM");
        String monthAndYear = calendar_view_format.format(date.getTime());
        return monthAndYear;
    }
});

이렇게 바꿨는데 달력을 넘기면 달력자체는 바뀌는데 제목은 계속 2020년 04월만 뜹니다

설명에는 

Header

You can customize the label displayed in the header by setting a custom TitleFormatter by calling setTitleFormatter(). The formatter's format() method will be called with a CalendarDay containing the month and year you should format. The default implementation uses a SimpleDateFormat with a format of "MMMM yyyy". The library provides a DateFormatTitleFormatter and MonthArrayTitleFormatter for convenience.

You can also set a string array resource with mcv_monthLabels that will use the MonthArrayTitleFormatter to format the title with the months provided.

 

출처:https://github.com/prolificinteractive/material-calendarview/wiki/Customization#topbar-options

 

이렇게 써져있는데 이해가 안되네요 도와주시면 정말 감사하겠습니다 

안드초보자1 (160 포인트) 님이 2020년 4월 20일 질문

2개의 답변

+1 추천
 
채택된 답변
setOnMonthChangedListener 안에 코드를 작성해보세요!
익명사용자 님이 2021년 2월 20일 답변
안드초보자1님이 2021년 2월 21일 채택됨
0 추천

저도 한참 해맸는데 

calendar_view_format.format(date.getTime())여기서

date가 아니라 day를 써야하네요

2년이나 지났지만 필요하신분이 있을수도 있어 답글 답니다

isoleth (260 포인트) 님이 2022년 11월 8일 답변
...