Android Calendar View of DatePicker

I use a date picker, on which I set the current date. when the view opened in bunch 7, together with the date finisher, we can see the calendar. the date counter is set correctly today, since I did this, but the calendar view displays 2100.

DatePickerDialog tempDialog = new DatePickerDialog(getActivity(), this, cur_year, cur_month, cur_day);
tempDialog.getDatePicker().setMinDate(today.getTimeInMillis());

as you see date spinner is proper, but calendar view is on year 2100 november

+4
source share
1 answer

Initiate the use of init for the dailog calendar.

        final Calendar calendarRange = Calendar.getInstance();
        final int maxYear = calendarRange.get(Calendar.YEAR);
        final int maxMonth = calendarRange.get(Calendar.MONTH);
        final int maxDay = calendarRange.get(Calendar.DAY_OF_MONTH);

        tempDialog.init(maxYear, maxMonth, maxDay,
                new OnDateChangedListener() {

                    public void onDateChanged(DatePicker view, int year,
                            int month, int day) {
                        Calendar newDate = Calendar.getInstance();
                        newDate.set(year, month, day);

                        if (calendarRange.before(newDate)) {
                            view.init(maxYear, maxMonth, maxDay, this);
                        }

                    }
                });

Then use this code:

Calendar cal = Calendar.getInstance();
int maxYear = cal.get(Calendar.YEAR);
int maxMonth = cal.get(Calendar.MONTH);
int maxDay = cal.get(Calendar.DAY_OF_MONTH);

DatePickerDialog dialog =
    new DatePickerDialog(this, mDateSetListener, maxYear , maxMonth , maxDay);
dialog.show();
0
source

Source: https://habr.com/ru/post/1535480/


All Articles