gpt4 book ai didi

java - 为什么时间选择器打不开?

转载 作者:行者123 更新时间:2023-12-02 02:32:27 25 4
gpt4 key购买 nike

我正在尝试检查所选时间是否在 11:30 - 14:30 之间或 17:00 - 22:30 之间。如果是,则检查时间是否早于当前时间 +20 分钟(或交货 +45 分钟)。

rdi_preorder.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {

EventBus.getDefault().postSticky(new EnableButtonNext(true));

final Calendar c = Calendar.getInstance();
int mHour = c.get(Calendar.HOUR_OF_DAY);
int mMin = c.get(Calendar.MINUTE);
final int currentHour = c.get(Calendar.HOUR_OF_DAY);
final int currentMinute = c.get(Calendar.MINUTE);
final int date = c.get(Calendar.DAY_OF_MONTH);
final int month = c.get(Calendar.MONTH);
final int year = c.get(Calendar.YEAR);


final TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(),
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hour, int min) {

selectedHour = hour;
selectedMin = min;

if (rdi_pickup.isChecked()) {
if (checkOpenTime(selectedHour, selectedMin))
if ((selectedDate == date && selectedMonth == month && selectedYear == year) &&
selectedHour * 60 + selectedMin < (currentHour * 60 + currentMinute + 20)) {
Toast.makeText(getContext(), "We are not able to finish your order so fast !Please preorder ahead!", Toast.LENGTH_SHORT).show();
if (rdi_now.getVisibility() == View.VISIBLE)
rdi_now.setChecked(true);
rdi_preorder.setChecked(false);
} else {
time_preorder = String.format("%2s:%2s %2s.%2s.%4s", selectedHour, selectedMin, selectedDate, selectedMonth, selectedYear);
txt_time.setVisibility(View.VISIBLE);
txt_time.setText(new StringBuilder("fur ").append(time_preorder).toString());
}

else {
Toast.makeText(getContext(), "Please order in our open times!", Toast.LENGTH_SHORT).show();
rdi_preorder.setChecked(false);
}
} else if (rdi_delivery.isChecked()) {
if (checkOpenTime(selectedHour, selectedMin)) {
if ((selectedDate == date && selectedMonth == month && selectedYear == year) &&
selectedHour * 60 + selectedMin < (currentHour * 60 + currentMinute + 45)) {
Toast.makeText(getContext(), "We are not able to deliver your order so fast !Please preorder ahead!", Toast.LENGTH_SHORT).show();
if (rdi_now.getVisibility() == View.VISIBLE)
rdi_now.setChecked(true);
rdi_preorder.setChecked(false);
}
else {
time_preorder = String.format("%2s:%2s %2s.%2s.%4s", selectedHour, selectedMin, selectedDate, selectedMonth, selectedYear);
txt_time.setVisibility(View.VISIBLE);
txt_time.setText(new StringBuilder("fur ").append(time_preorder).toString());
}
else
Toast.makeText(getContext(), "Please order in our open times!", Toast.LENGTH_SHORT).show();
rdi_preorder.setChecked(false);} } }

}, mHour, mMin, true);

timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {

}}); } }}

我想测试我的代码,但如果我单击 rdi_preorder,则日期和时间选择器不会打开。请帮忙

最佳答案

调用timePickerDialog.show()来告诉对话框出现在屏幕上

关于java - 为什么时间选择器打不开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57222608/

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