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

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

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

        Android Dialog,按下按钮时保持对话框打开

        时间:2023-08-31

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

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

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

                  本文介绍了Android Dialog,按下按钮时保持对话框打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在按下按钮时保持对话框打开.目前它正在关闭.

                  I would like to keep my dialog open when I press a button. At the moment it's closing.

                  AlertDialog.Builder builder = new AlertDialog.Builder(this);
                  
                  builder.setMessage("Are you sure you want to exit?")
                  
                     .setCancelable(false)
                     .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                         public void onClick(DialogInterface dialog, int id) {
                              MyActivity.this.finish();
                         }
                     })
                     .setNegativeButton("No", new DialogInterface.OnClickListener() {
                         public void onClick(DialogInterface dialog, int id) {
                              dialog.cancel();
                         }
                     });
                  AlertDialog alert = builder.create();
                  

                  推荐答案

                  是的,你可以.你基本上需要:

                  Yes, you can. You basically need to:

                  1. 使用 DialogBu​​ilder
                  2. 创建对话框
                  3. show() 对话框
                  4. 在显示的对话框中找到按钮并覆盖它们的 onClickListener

                  所以,创建一个监听器类:

                  So, create a listener class:

                  class CustomListener implements View.OnClickListener {
                    private final Dialog dialog;
                  
                    public CustomListener(Dialog dialog) {
                      this.dialog = dialog;
                    }
                  
                    @Override
                    public void onClick(View v) {
                  
                      // Do whatever you want here
                  
                      // If you want to close the dialog, uncomment the line below
                      //dialog.dismiss();
                    }
                  }
                  

                  然后在显示对话框时使用:

                  Then when showing the dialog use:

                  AlertDialog dialog = dialogBuilder.create();
                  dialog.show();
                  Button theButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
                  theButton.setOnClickListener(new CustomListener(dialog));
                  

                  请记住,您需要显示对话框,否则将无法找到该按钮.此外,请务必将 DialogInterface.BUTTON_POSITIVE 更改为您用于添加按钮的任何值.另请注意,在 DialogBu​​ilder 中添加按钮时,您需要提供 onClickListeners - 但是,您不能在其中添加自定义侦听器 - 如果您在调用 show() 后不要覆盖监听器.

                  Remember, you need to show the dialog otherwise the button will not be findable. Also, be sure to change DialogInterface.BUTTON_POSITIVE to whatever value you used to add the button. Also note that when adding the buttons in the DialogBuilder you will need to provide onClickListeners - you can not add the custom listener in there, though - the dialog will still dismiss if you do not override the listeners after show() is called.

                  这篇关于Android Dialog,按下按钮时保持对话框打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Android - 如何在本机屏幕上显示对话框? 下一篇:Android 对话框:删除标题栏

                  相关文章

                  最新文章

                    1. <legend id='kd8Nw'><style id='kd8Nw'><dir id='kd8Nw'><q id='kd8Nw'></q></dir></style></legend>

                      <tfoot id='kd8Nw'></tfoot>
                        <bdo id='kd8Nw'></bdo><ul id='kd8Nw'></ul>

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

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