不要通过点击一个按钮来关闭alertdialog - Android电子 [英] Do not close the alertdialog by clicking on a button - Android

查看:890
本文介绍了不要通过点击一个按钮来关闭alertdialog - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个alertdialog任何选项和2个按钮。我不希望关闭该对话框,当我推的第二个按钮(仅停止声音)。

有没有财产,以保持对话框打开?

感谢你了!

code:

 公共无效creaDialogTo(){            最终的String [] =托诺斯{thinks.mp3,life.mp3,war.mp3};            AlertDialog.Builder建设者=新AlertDialog.Builder(本);            builder.setTitle(选择);
            builder.setCancelable(假);
            builder.setSingleChoiceItems(色调,-1,新DialogInterface.OnClickListener(){
                公共无效的onClick(DialogInterface对话,诠释项){
                    音=音调[项目];
                    Sound1例子=新SoundManager类(getApplicationContext());
                    sound1.loadSound(音[项目]);
                }
            });
            builder.setPositiveButton(确认,
                    新DialogInterface.OnClickListener(){
                        公共无效的onClick(DialogInterface对话,诠释的id){
                            pref.setTone(音);                            sound1.stopsound();                        }
                    });
            builder.setNeutralButton(停止音,
                    新DialogInterface.OnClickListener(){
                        公共无效的onClick(DialogInterface对话,诠释的id){
                        sound1.stopsound();                        }
                    });
            AlertDialog警报= builder.create();
            alert.show();    }


解决方案

我猜,你是显示AlertDialog,使用默认的按钮正负。相反,你可以创建一个对话框,并手动设置一个布局该对话框的内容查看,具有两个按钮。在这里,您需要定义按钮点击事件的所有定义,并且不会发生默认按钮。所以,如果你不点击一个按钮驳回对话,只是不调用dialog.dismiss(),在按钮的点击。

编辑:中性按钮默认情况下关闭该对话框,请修改为负的按钮,如果它仍然不会工作,那么请申请的解决方案,我上面写的

I've an alertdialog any options and with 2 buttons. I don't want close the dialog when I push on the second button (only stop a sound).

Is there any property to maintain the dialog open?

Thank you so much!

Code:

        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(); 

    }

解决方案

I guess, You are displaying AlertDialog, with default buttons Positive and Negative. instead, you can create a Dialog, and set a layout as contentView of this dialog, with having two buttons, manually. Here you would need to define all the definition of the button click event, and no default button will occur. So, If you are not dismissing dialog on a button click, simply dont invoke dialog.dismiss(), on button click.

Edit: Neutral Button by default dismiss the dialog, try changing it as negative button, if it still wont work, then please apply solution, I have written above.

这篇关于不要通过点击一个按钮来关闭alertdialog - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆