gpt4 book ai didi

android - TimePickerDialog 在设置时自动关闭

转载 作者:行者123 更新时间:2023-11-29 01:35:44 27 4
gpt4 key购买 nike

我如何禁用 TimePickerDialog 在按下设置时关闭?

我需要检查值是否合适,如果不是,我不希望它被忽略。

mTimePicker.setCancelable(true);

但我确实希望用户能够通过取消...

    TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker,
int selectedHour, int selectedMinute) {

if(condition){
mTimePicker.dismiss();

}else{
showMessage();
}

}
}, hour, minute, false);// Yes 24 hour time
mTimePicker.setTitle(getString(R.string.select_time));

mTimePicker.show();

最佳答案

我将给出 Jesus Dimrix 的示例代码再次调用 mTimepicker.show() 的“唯一解决方案”。

Calendar c = Calendar.getInstance();
final int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);

timePickerDialog = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
if(hourOfDay > 12){
timePickerDialog = new TimePickerDialog(MainActivity.this,this,hourOfDay,minute,true);
timePickerDialog.show();
Toast.makeText(MainActivity.this,"Must be less than 12",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this,hourOfDay + ":" + minute,Toast.LENGTH_SHORT).show();
}
}
}, hour, minute, true);
timePickerDialog.show();

我希望其他人能给出更好的解决方案。

关于android - TimePickerDialog 在设置时自动关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28212810/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com