Пожалуйста, измените CustomCalendarView Класс, как указано ниже
public class CustomCalendarView extends LinearLayout {
private static final int MAX_CALENDAR_DAYS = 42;
ImageView backBtn, nextBtn;
TextView CurrentDate;
GridView gridViewCalendar;
Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
Context myContext;
SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM yyyy", Locale.ENGLISH);
SimpleDateFormat monthFormat = new SimpleDateFormat("MMMM", Locale.ENGLISH);
SimpleDateFormat yearFormat = new SimpleDateFormat("MMMM YYYY", Locale.ENGLISH);
List<Date> dates = new ArrayList<>();
List<Events> eventsList = new ArrayList<>();
public CustomCalendarView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.myContext = context;
InitializeLayout();
SetUpCalendar();
backBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
calendar.add(Calendar.MONTH, -1);
SetUpCalendar();
}
});
nextBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
calendar.add(Calendar.MONTH, 1);
SetUpCalendar();
}
});
}
private void SetUpCalendar() {
String currentDate = dateFormat.format(calendar.getTime());
CurrentDate.setText(currentDate);
}
public void InitializeLayout() {
LayoutInflater inflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.custom_calendar, this);
nextBtn = view.findViewById(R.id.forwardButton);
backBtn = view.findViewById(R.id.previousButton);
CurrentDate = view.findViewById(R.id.currentDate);
gridViewCalendar = view.findViewById(R.id.gridview);
}
}
Работает хорошо
I надеюсь, это поможет вам!
Спасибо.