Home > Enterprise >  calendarView is not shown the correct months
calendarView is not shown the correct months

Time:09-11

The calendarView it always shows a month before the chosen one, example: I choose 20/02/2002, calendarView min returns 20/01/2002. Como eu faço pra que seja recuperado ao clicar o mês correto ?

My calendarView:

calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @Override
            public void onSelectedDayChange(@NonNull CalendarView calendarView, int year, int month, int day) {
                String data = dia "/" mes "/" ano;
                Toast.makeText(PagamentoActivity.this, data, Toast.LENGTH_SHORT).show();
            }
        });

CodePudding user response:

    public interface OnDateChangeListener {

    /**
     * Called upon change of the selected day.
     *
     * @param view The view associated with this listener.
     * @param year The year that was set.
     * @param month The month that was set [0-11].
     * @param dayOfMonth The day of the month that was set.
     */
    void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth);
}

month index start with zero

CodePudding user response:

It is because the month starts with 0 and not 1, try using this it will work for you:

calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
        @Override
        public void onSelectedDayChange(@NonNull CalendarView calendarView, int year, int month, int day) {
            String data = day "/" (month 1) "/" year;
            Toast.makeText(PagamentoActivity.this, data, Toast.LENGTH_SHORT).show();
        }
    });
  • Related