private int mHour, mMinute;
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
// Launch Time Picker Dialog
TimePickerDialog timePickerDialog = new TimePickerDialog(ActivityScheduleTransfer.this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
final Calendar checkOldDate = Calendar.getInstance();
if (hourOfDay >= checkOldDate.get(Calendar.HOUR_OF_DAY)) {
if (hourOfDay == checkOldDate.get(Calendar.HOUR_OF_DAY) && minute <= checkOldDate.get(Calendar.MINUTE)) {
return;
}
//select current after
} else {`enter code here`
//select current before
}
}
}, mHour, mMinute, false);
timePickerDialog.show();
3条答案
按热度按时间ttygqcqt1#
请尝试以下代码:
它将显示
timepicker
对话框,如果用户选择当前时间之前的任何时间...它将显示无效时间..编辑您需要导入:
这里是一个好的Example
prdp8dxp2#
最好的解决方案是使用this材料设计库来选择时间或日期并设置最小值。
将Material DateTime Picker库添加到项目的最简单方法是将其作为依赖项添加到构建版本。gradle
46qrfjad3#