我正在使用这段代码来设置日期选择器的自定义日期... // 创建日期选择器对话框的方法
public static class DatePickerFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// set default date
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// get selected date
mYear = year;
mMonth = month;
mDay = day;
// show selected date to date button
dob.setText(new StringBuilder()
.append(mYear).append("-")
.append(mMonth + 1).append("-")
.append(mDay).append(" "));
}
}
我的情况是,每当用户设置一个日期时,日期应该验证用户至少18岁。否则,它会显示警告用户至少18岁。