Возможно, будет слишком поздно ответить, но для DatePickerDialog
легко установить дату min
и max
. Работает для всех версий Android . Просто вам нужно вернуть DatePickerDialog
в зависимости от версии Android
protected Dialog onCreateDialog(int id)
{
switch ( id )
{
case DATE_DIALOG_ID:
DatePickerDialog dialog = null;
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB )
{
dialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDate)
{
mTextView.setText(selectedDate + "/" + selectedMonth + 1 + "/" + selectedYear);
}
}, year, month - 1, date);
Calendar currentDate = Calendar.getInstance();
dialog.getDatePicker().setMaxDate(currentDate.getTimeInMillis());
//If you need you can set min date too
}
else
{
dialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDate)
{
mTextView.setText(selectedDate + "/" + selectedMonth + 1 + "/" + selectedYear);
}
}, year, month - 1, date)
{
@Override
public void onDateChanged(DatePicker view, int year, int month, int day)
{
if ( year <= maxYear && month + 1 <= maxMonth && date <= maxDate ) //meets your criteria
{
view.updateDate(year, month, date); //update the date picker to selected date
}
else
{
view.updateDate(maxYear, maxMonth - 1, maxDate); // or you update the date picker to previously selected date
}
}
};
}
return dialog;
}
return null;
}