How to disable future date in calender in android application?

case DATE_DIALOG_ID:
int       intMaxYear =  cyear – 10;
int    intMaxMonth = cmonth;
int    intMaxDay =  cday;

int    intMinYear =  cyear – 150;
int    intMinMonth = cmonth;
int    intMinDay =  cday;

DatePickerDialog   datePickerDialog = new DatePickerDialogWithMaxMinRange(
this, mDateSetListener,intMinYear,intMinMonth,intMinDay,intMaxYear,intMaxMonth,intMaxDay);
return datePickerDialog;

***************************************************************************
DatePickerDialogWithMaxMinRange.class
public class DatePickerDialogWithMaxMinRange extends DatePickerDialog {

static int maxYear;
static int maxMonth;
static int maxDay;

int minYear;
int minMonth;
int minDay;

public DatePickerDialogWithMaxMinRange(Context context,  OnDateSetListener callBack,int minYear,int minMonth,int minDay,int maxYear,int maxMonth,int maxDay) {
super(context,callBack, maxYear, maxMonth, maxDay);
this.minDay = minDay;
this.minMonth = minMonth;
this.minYear = minYear;
DatePickerDialogWithMaxMinRange.maxDay = maxDay;
DatePickerDialogWithMaxMinRange.maxMonth = maxMonth;
DatePickerDialogWithMaxMinRange.maxYear = maxYear;
}

@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
super.onDateChanged(view, year, monthOfYear, dayOfMonth);

if (year > maxYear ||monthOfYear > maxMonth && year == maxYear||
dayOfMonth > maxDay && year == maxYear && monthOfYear == maxMonth){
view.updateDate(maxYear, maxMonth, maxDay);
}else if(year < minYear ||monthOfYear < minMonth && year == minYear||
dayOfMonth < minDay && year == minYear && monthOfYear == minMonth){
view.updateDate(minYear, minMonth, minDay );
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website