简体   繁体   English

DatePicker的Android日历视图

[英]Android Calendar View of DatePicker

I am using a date picker to which i set the current date. 我正在使用日期选择器来设置当前日期。 when the view in opened in a nexus 7, along with date spinner we can see a calendar. 当在nexus 7中打开视图时,与日期微调器一起我们可以看到日历。 the date spinner is properly set to today as i made it to be but the calendar view is displaying 2100 year. 日期微调器已正确设置为今天,因为日历视图显示2100年。

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

如您所见,日期微调器是正确的,但日历视图是在2100年11月

to Initiate use init for the calender dailog. 启动日历dailog的使用init。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM