【问题标题】:Dialog shows only the second time a button is pressed to activate it对话框仅显示第二次按下按钮以激活它
【发布时间】:2012-07-11 14:32:10
【问题描述】:

我对@9​​87654321@ 和DatePickerDialog 有一些问题, 代码如下:

public void onClick(View v) {
    if (v.equals(checkInTime)) {
        showDialog(1);
    }

@Override
protected Dialog onCreateDialog(int id) {
    if (id == 1) {
        return new TimePickerDialog(this, this, dt.getHourOfDay(), dt.getMinuteOfHour(), true);
    }

    return super.onCreateDialog(id);
}

它就像一个魅力,直到我在对话框中按下“设置”,然后下次我点击按钮时什么也没有发生(对话框没有出现),但如果我再点击一次,对话框再次显示。它每次都会显示,直到我按“设置”然后单击它才不起作用,但在下次单击时再次开始工作。

DatePickerDialog 也会出现同样的问题。有人有什么想法吗?

监听器没有做任何事情。

【问题讨论】:

    标签: android dialog show-hide timepicker android-datepicker


    【解决方案1】:

    在您的对话框中调用dismiss() (TimePickerDialog) 是问题所在。与调用cancel()onBackPress() 相同,因为它调用dismiss()。相反,您可以致电hide()

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题。
      在模拟器上一切正常,但在三星 Galaxy Note [android 4] 上,每秒钟显示一次 DialogDatePicker 失败。我怀疑隐藏/关闭 DialogDatePicker 是错误的。

      为“确定”按钮添加侦听器后,一切都开始正常工作了。

      DatePickerDialog dpd = new DatePickerDialog(this, callBack, fakeYear, fakeMonth, fakeDay);
      dpd.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
               System.out.println("here nothing more is needed");
               System.out.println("dialog closed and next time appear again");
            }
         }
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-09
        • 1970-01-01
        • 2020-01-23
        • 1970-01-01
        • 2012-07-05
        • 1970-01-01
        • 2021-03-16
        • 1970-01-01
        相关资源
        最近更新 更多