我试图限制日期和时间。我希望如果用户尝试将日期设置为小于当前日期,那么它应该显示警报,并且同样的事情是用时间来完成的。我正在使用日期和时间选择器,我的onDateSetListener
和onTimeSetListener
如下:
DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
dateTime.set(Calendar.YEAR, year);
dateTime.set(Calendar.MONTH, monthOfYear);
dateTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
update_date_display();
// ---for setting notification----
day = dayOfMonth;
month = monthOfYear;
AddEditTask.year = year;
c.set(year, month, day);
}
};
protected void update_date_display() {
et_task_date.setText(formatDate.format(dateTime.getTime()));
}
TimePickerDialog.OnTimeSetListener t = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
dateTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
dateTime.set(Calendar.MINUTE, minute);
update_time_display();
// ---for setting notification---
hour = hourOfDay;
AddEditTask.minute = minute;
c.set(Calendar.HOUR_OF_DAY, hourOfDay);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, 0);
}
};
private void update_time_display() {
et_task_time.setText(formatTime.format(dateTime.getTime()));
}
你能告诉我在这些听众中要写什么来实现我想要的吗?提前致谢...!!!