【问题标题】:Do not close the alertdialog by clicking on a button - Android不要通过单击按钮关闭警报对话框 - Android
【发布时间】:2012-09-11 04:50:01
【问题描述】:

我有一个 alertdialog 任何选项和 2 个按钮。当我按下第二个按钮时,我不想关闭对话框(仅停止声音)。

是否有任何属性可以保持对话框打开?

非常感谢!

代码:

        public void creaDialogTo(){

            final String[] tonos = {"thinks.mp3", "life.mp3", "war.mp3"};

            AlertDialog.Builder builder = new AlertDialog.Builder(this);

            builder.setTitle("Select");
            builder.setCancelable(false);
            builder.setSingleChoiceItems(tones, -1,new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    tone=tones[item];
                    sound1 =new SoundManager(getApplicationContext());
                    sound1.loadSound(tones[item]);


                }
            });
            builder.setPositiveButton("Confirm",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            pref.setTone(tone);

                            sound1.stopsound();

                        }
                    });
            builder.setNeutralButton("Stop sound",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                        sound1.stopsound();

                        }
                    });
            AlertDialog alert = builder.create();
            alert.show(); 

    }

【问题讨论】:

  • 可以发布您用于警报对话框的代码
  • @Ramkiran 谢谢,这是代码
  • 然后仅在确认按钮处调用 builder.dismiss()。无需调用停止按钮的解除方法

标签: android android-alertdialog


【解决方案1】:

我猜,您正在显示 AlertDialog,带有默认按钮 Positive 和 Negative。相反,您可以创建一个对话框,并将布局设置为此对话框的 contentView,并手动设置两个按钮。在这里您需要定义按钮单击事件的所有定义,并且不会出现默认按钮。因此,如果您没有在单击按钮时关闭对话框,请不要在单击按钮时调用 dialog.dismiss()。

编辑:中性按钮默认关闭对话框,尝试将其更改为否定按钮,如果仍然无法使用,请申请解决方案,我在上面写过。

【讨论】:

  • 否定按钮的作用相同:(
  • 请创建一个对话框,并将此对话框的 ContentView 设置为具有这些按钮的布局。
猜你喜欢
  • 1970-01-01
  • 2011-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多