Skip to content

Instantly share code, notes, and snippets.

@christianroman
Last active December 25, 2015 02:59
Show Gist options
  • Save christianroman/6906630 to your computer and use it in GitHub Desktop.
Save christianroman/6906630 to your computer and use it in GitHub Desktop.
Custom DatePickerDialog class with min date (API Level < 11)
package com.chroman.test;
import android.app.DatePickerDialog;
import android.content.Context;
import android.widget.DatePicker;
/**
* Created by chroman on 09/10/13.
*/
public class DatePickerDialogWithMinRange extends DatePickerDialog {
int minYear = 1955;
int minMonth = 0;
int minDay = 1;
public DatePickerDialogWithMinRange(Context context, OnDateSetListener callBack, int year, int month, int day) {
super(context,callBack, year, month, day);
this.minDay = day;
this.minMonth = month;
this.minYear = year;
}
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
super.onDateChanged(view, year, monthOfYear, dayOfMonth);
if(year < minYear ||monthOfYear < minMonth && year == minYear ||
dayOfMonth < minDay && year == minYear && monthOfYear == minMonth){
view.updateDate(minYear, minMonth, minDay);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment