• <bdo id='T6Euu'></bdo><ul id='T6Euu'></ul>
  • <tfoot id='T6Euu'></tfoot>
      <legend id='T6Euu'><style id='T6Euu'><dir id='T6Euu'><q id='T6Euu'></q></dir></style></legend>

        <small id='T6Euu'></small><noframes id='T6Euu'>

        <i id='T6Euu'><tr id='T6Euu'><dt id='T6Euu'><q id='T6Euu'><span id='T6Euu'><b id='T6Euu'><form id='T6Euu'><ins id='T6Euu'></ins><ul id='T6Euu'></ul><sub id='T6Euu'></sub></form><legend id='T6Euu'></legend><bdo id='T6Euu'><pre id='T6Euu'><center id='T6Euu'></center></pre></bdo></b><th id='T6Euu'></th></span></q></dt></tr></i><div id='T6Euu'><tfoot id='T6Euu'></tfoot><dl id='T6Euu'><fieldset id='T6Euu'></fieldset></dl></div>

      1. Android-显示自定义对话框

        时间:2023-06-27
          <tbody id='ObRxY'></tbody>

        • <tfoot id='ObRxY'></tfoot>

          <i id='ObRxY'><tr id='ObRxY'><dt id='ObRxY'><q id='ObRxY'><span id='ObRxY'><b id='ObRxY'><form id='ObRxY'><ins id='ObRxY'></ins><ul id='ObRxY'></ul><sub id='ObRxY'></sub></form><legend id='ObRxY'></legend><bdo id='ObRxY'><pre id='ObRxY'><center id='ObRxY'></center></pre></bdo></b><th id='ObRxY'></th></span></q></dt></tr></i><div id='ObRxY'><tfoot id='ObRxY'></tfoot><dl id='ObRxY'><fieldset id='ObRxY'></fieldset></dl></div>

            1. <small id='ObRxY'></small><noframes id='ObRxY'>

              • <bdo id='ObRxY'></bdo><ul id='ObRxY'></ul>
                <legend id='ObRxY'><style id='ObRxY'><dir id='ObRxY'><q id='ObRxY'></q></dir></style></legend>
                  本文介绍了Android-显示自定义对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的 android 应用程序中,我使用的是自定义对话框.当我尝试显示对话框时,会导致错误.我不知道我做错了什么,我真的很困惑.

                  In my android application, I am using a custom dialog. When I try to show the dialog, it causes an error. I don't know what I am doing wrong, and I am really confused.

                  这是我的代码:

                  protected Dialog onCreateDialog(int id) {
                      Dialog dialog;
                      switch(id) {
                      case 0:
                          dialog = new Dialog(getApplicationContext());
                  
                          dialog.setContentView(R.layout.paused);
                          dialog.setTitle("Game Paused");
                          dialog.show();
                          break;
                      default:
                          dialog = null;
                      }
                      return null;
                  }
                  

                  这是我显示对话框的方式

                  And here is how I show the dialog

                  showDialog(0);
                  

                  顺便说一句,它说 showDialog(int) 已被弃用.

                  By the way, it says that showDialog(int) is deprecated.

                  Android 日志:

                  Android logcat:

                  > 06-19 18:44:22.399: W/dalvikvm(467): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
                  06-19 18:44:22.419: E/AndroidRuntime(467): FATAL EXCEPTION: main
                  06-19 18:44:22.419: E/AndroidRuntime(467): java.lang.IllegalStateException: Could not execute method of the activity
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.View$1.onClick(View.java:2072)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.View.performClick(View.java:2408)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.View$PerformClick.run(View.java:8816)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.os.Handler.handleCallback(Handler.java:587)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.os.Handler.dispatchMessage(Handler.java:92)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.os.Looper.loop(Looper.java:123)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.ActivityThread.main(ActivityThread.java:4627)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at java.lang.reflect.Method.invokeNative(Native Method)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at java.lang.reflect.Method.invoke(Method.java:521)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at dalvik.system.NativeStart.main(Native Method)
                  06-19 18:44:22.419: E/AndroidRuntime(467): Caused by: java.lang.reflect.InvocationTargetException
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at com.jlennon.gametest.PlayGameActivity.pause(PlayGameActivity.java:105)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at java.lang.reflect.Method.invokeNative(Native Method)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at java.lang.reflect.Method.invoke(Method.java:521)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.View$1.onClick(View.java:2067)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  ... 11 more
                  06-19 18:44:22.419: E/AndroidRuntime(467): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.ViewRoot.setView(ViewRoot.java:509)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Dialog.show(Dialog.java:241)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at com.jlennon.gametest.PlayGameActivity.onCreateDialog(PlayGameActivity.java:131)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Activity.onCreateDialog(Activity.java:2472)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Activity.createDialog(Activity.java:881)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Activity.showDialog(Activity.java:2547)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Activity.showDialog(Activity.java:2514)
                  06-19 18:44:22.419: E/AndroidRuntime(467):  ... 15 more
                  

                  提前非常感谢!

                  推荐答案

                  试试这个代码

                   protected Dialog onCreateDialog(int id) {
                    Dialog dialog;
                    switch(id) {
                     case 0:
                      dialog = new Dialog(this);
                  
                      dialog.setContentView(R.layout.paused);
                      dialog.setTitle("Game Paused");
                      dialog.show();
                      break;
                  default:
                      dialog = null;
                  }
                  return null;
                  

                  }

                  我刚刚将 dialog = new Dialog(getApplicationContext()) 替换为 dialog = new Dialog(this);

                  I just replaced dialog = new Dialog(getApplicationContext()) to dialog = new Dialog(this);

                  这篇关于Android-显示自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:JavaFX 创建警报并获得结果 下一篇:单击中性按钮后是否可以保持对话框打开?

                  相关文章

                    • <bdo id='9ZMb6'></bdo><ul id='9ZMb6'></ul>
                  1. <i id='9ZMb6'><tr id='9ZMb6'><dt id='9ZMb6'><q id='9ZMb6'><span id='9ZMb6'><b id='9ZMb6'><form id='9ZMb6'><ins id='9ZMb6'></ins><ul id='9ZMb6'></ul><sub id='9ZMb6'></sub></form><legend id='9ZMb6'></legend><bdo id='9ZMb6'><pre id='9ZMb6'><center id='9ZMb6'></center></pre></bdo></b><th id='9ZMb6'></th></span></q></dt></tr></i><div id='9ZMb6'><tfoot id='9ZMb6'></tfoot><dl id='9ZMb6'><fieldset id='9ZMb6'></fieldset></dl></div>
                  2. <legend id='9ZMb6'><style id='9ZMb6'><dir id='9ZMb6'><q id='9ZMb6'></q></dir></style></legend>

                    <small id='9ZMb6'></small><noframes id='9ZMb6'>

                      <tfoot id='9ZMb6'></tfoot>