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

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

        • <bdo id='IjMTs'></bdo><ul id='IjMTs'></ul>

        Android 对话框自行消失

        时间:2023-08-30

            <bdo id='hadI9'></bdo><ul id='hadI9'></ul>

                <tbody id='hadI9'></tbody>
                1. <tfoot id='hadI9'></tfoot>
                2. <legend id='hadI9'><style id='hadI9'><dir id='hadI9'><q id='hadI9'></q></dir></style></legend>

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

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

                  本文介绍了Android 对话框自行消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用以下代码来创建自己的对话框:

                  I'm using the following code to create my own dialog:

                  public void ShowMessageDialog(String str){
                      AlertDialog.Builder builder = new AlertDialog.Builder(this);
                      builder.setMessage(str);
                      builder.setCancelable(false);
                      builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {          
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                              dialog.dismiss();
                          }
                      });
                      AlertDialog alert = builder.create();
                      alert.show();
                  }
                  

                  它工作正常,但在此函数中使用时,对话框会自行消失:

                  It works fine but it appears the Dialog disappears on it's own when used inside this function:

                  public void test(String str){
                      ShowMessageDialog("About to start new activity");
                      Intent intent = new Intent(this,PageViewer.class);
                      startActivity(intent);
                  }
                  

                  似乎新活动已创建并且显然摆脱了对话框.但为什么?活动不应该在打开新活动之前停止吗?

                  It seems that the new activity is created and obviously gets rid of the dialog. But why? Shouldn't the activity stop before opening the new one?

                  谢谢!

                  推荐答案

                  即将触发的 Intent 不会等待您的对话框被取消.因此,在显示对话框后,新的活动就开始了.你可以像这样完成你想要的:

                  Intent which is about to fire doesn't wait for your dialog to be canceled. So, right after dialog is shown, new Activity is started. You could accomplish what you want like this:

                  public void ShowMessageDialog(String str){
                      AlertDialog.Builder builder = new AlertDialog.Builder(this);
                      builder.setMessage(str);
                      builder.setCancelable(false);
                      builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {          
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                              dialog.dismiss();
                              Intent intent = new Intent(this,PageViewer.class);
                              startActivity(intent);
                          }
                      });
                      AlertDialog alert = builder.create();
                      alert.show();
                  }
                  
                  public void test(String str){
                      ShowMessageDialog("About to start new activity");
                  }
                  

                  这篇关于Android 对话框自行消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何通过代码在 AlertDialog 上单击“确定"? 下一篇:在android中显示对话框时我们可以与后台活动交互

                  相关文章

                  最新文章

                    • <bdo id='IQzgB'></bdo><ul id='IQzgB'></ul>

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