1

我有一个 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(); 

    }
4

1 回答 1

5

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

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

于 2012-09-11T04:59:48.637 回答