javaandroidcalendarview

calendarView is not shown the correct months


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();
            }
        });

Solution

  • 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();
            }
        });