我打算将时间选择器阻止到特定的开始时间和结束时间。为此,我正在设置 TimeChangedListener 并覆盖 onTimeChanged 方法。下面是 onTimeChanged() 的实现。
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
//;super.onTimeChanged(view, hourOfDay, minute);
try{
boolean flag = true;
if (hourOfDay <= maxHour && hourOfDay >= minHour) {
if (hourOfDay == maxHour && hourOfDay == minHour) {
if (minute > maxMin)
flag = false;
else if (minute < minMin)
flag = false;
else if (minute == maxMin && minute == minMin) {
flag = false;
} else if (minute == maxMin) {
flag = false;
} else if (minute == minMin) {
flag = false;
}
} else if (hourOfDay == maxHour) {
if (minute > maxMin)
{
flag = false;
}
} else if (hourOfDay == minHour) {
if (minute < minMin)
flag = false;
}
if (flag) {
curHour = hourOfDay;
curMin = minute;
} else {
updateTime(curHour, curMin);
}
//(curYear, curMonth);
} else {
updateTime(curHour, curMin);
}
//view.updateDate(curYear, curMonth, curDay);
} catch (Exception e) {
Log.e("CustomTimePicker","error");
}
}
但是当我达到最短时间并尝试再次减少分钟时间时,使用此代码片段,它会从第一个开始继续循环
updateTime(curHour, curMin);
方法调用并获取堆栈溢出异常。机器人工作正常(如预期)数小时更新。因此,如果有人查看代码片段并发现问题,请告诉我。任何帮助将不胜感激。
提前致谢。