I use Calendar on EditText
click to select birth date of user and set it in EditText
. It works fine in all devices. But only in Swipe Sonic 4.1.2 (API 16) it shows years up to 1980. User can not select year lower than 1980.
Here is my Code:
demo.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
DateDialog();
}
}
});
public void DateDialog() {
try {
DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
demo.setText(dayOfMonth + "/" + (monthOfYear + 1) + "/" + year);
edt_contact.requestFocus();
// checking for age should be 18 years and above
Calendar userAge = new GregorianCalendar(year, monthOfYear, dayOfMonth);
Calendar minAdultAge = new GregorianCalendar();
minAdultAge.add(Calendar.YEAR, -18);
if (minAdultAge.before(userAge)) {
Toast.makeText(getApplicationContext(), "Age should be 18 and above", Toast.LENGTH_LONG).show();
demo.setText("");
// demo.requestFocus();
}
}
};
DatePickerDialog dpDialog = new DatePickerDialog(this, listener, year, month, day);
dpDialog.setCancelable(true);
dpDialog.show();
} catch (Exception e)
{
e.printStackTrace();
logsdata.logsdata("MainActivty", "DateDialog", e.getMessage().toString());
}
}//DateDialog