Android – include date selector in maximum date

I'm trying to use the Android date selector to select a date range through two inputs. The start date takes the end date as its maximum date and the end date takes the start date as its minimum date

I want to allow the date selector to be set to the same date to allow a day to be selected as the range (because the range is included)

However, it seems that the minimum date is included and the maximum date is always excluded? Is there any way to include the maximum date? Now, the date selector sets the end date to an optional style, but not (I really hate it because it's confusing). It finally looks like this (February 28 is allowed as the maximum optional date - note that March 1 looks optional, but not):

@L_ 301_ 1@

I didn't do anything special in the code. Just create a DatePickerDialog and then call dialog.getDatePicker ().SetMaxDate (maxDateInMs).

resolvent:

I realized that both minday and maxday were included

final Calendar myCalendar = Calendar.getInstance();
DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
    }
};

DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, date, myCalendar
        .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
        myCalendar.get(Calendar.DAY_OF_MONTH));

datePickerDialog.getDatePicker().setMinDate(myCalendar.getTimeInMillis());
datePickerDialog.getDatePicker().setMaxDate(myCalendar.getTimeInMillis()+ DateUtils.DAY_IN_MILLIS);

datePickerDialog.show();

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>