I am trying to set the min and max date of the date picker in Android to before API level 11. I used the following code:
mDatePickerField = startDatePickerDi
You can set range with init datePicker method. Example with min value :
// Calendar
this.calendar = new GregorianCalendar();
this.datePicker = (DatePicker) findViewById(R.id.xxxxx);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// (picker is a DatePicker)
this.datePicker.setMinDate(this.calendar.getTimeInMillis());
} else {
final int minYear = this.calendar.get(Calendar.YEAR);
final int minMonth = this.calendar.get(Calendar.MONTH);
final int minDay = this.calendar.get(Calendar.DAY_OF_MONTH);
this.datePicker.init(minYear, minMonth, minDay,
new OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year,
int month, int day) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, month, day);
if (calendar.after(newDate)) {
view.init(minYear, minMonth, minDay, this);
}
}
});
Log.w(TAG, "API Level < 11 so not restricting date range...");
}