I'm working on a form to input user info. There's an EditText
to set the date of birth. tapping on it opens a DatePickerDialogue
. I want to set limit on the date to current date so that user cannot select date from the future.
Here's my Code:
DatePickerDialog.OnDateSetListener dpd;
Edittext etDOB = (EditText) findViewById(R.id.etDate);
etDOB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerDialog(ActivityCustomerInfo.this,dpd,calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
dpd=new DatePickerDialog.OnDateSetListener(){
@Override
public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, monthOfYear);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
String month = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
etDOB.setText(new StringBuilder().append((month)+" ").append((dayOfMonth)+", ").append(year));
}
};
I know a function setMaxDate() but cannot understand how to apply it to my code.
I followed the answers here but the code doesn't seem to match with mine.