if your application requires to run on API LEVEL 8+ then use below way to do it. put the relevant code inside yout onDateSet
method.
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
String selected_date = dayOf + "-" + monthOf + "-" + year;
Log.i(TAG, "Selected Date" + selected_date);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date strDate = null;
try {
strDate = sdf.parse(selected_date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Calendar c = Calendar.getInstance();
System.out.println("Current time => " + c.getTime());
Date current_date = null;
String formattedDate = sdf.format(c.getTime());
try {
current_date = sdf.parse(formattedDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (current_date.after(strDate)) {
Toast.makeText(getApplicationContext(),
"Please choose future date", 1).show();
} else {
mYear = String.valueOf(year);
mMonth = String.valueOf(monthOfYear);
mDay = String.valueOf(dayOfMonth);
updateStartDate();
}
}
if your Application require to run on API LEVEL 11+ then use DatePicker.setMinDate(long)
you can find more information HERE