android - 警报对话框生成器确认按钮

标签 android android-alertdialog

在我的应用程序中,我使用了警报对话框生成器来单击按钮。因此,当我按下按钮时,会打开一个小弹出窗口,其中包含选项 - 激活和停用。那么,当用户按下“激活”或“停用”时,我可以做到这一点吗?确认窗口会打开,并带有问题“您确定吗?”以及选择是或否??

最佳答案

我在另一个对话框中创建了对话框。

查看这段代码:

twsbiSelectionMenuDialog = new Dialog(this,R.style.CustomDialogTheme);
            twsbiSelectionMenuDialog.setContentView(R.layout.twsbi_selection_menu_dialog);
            twsbiSelectionMenuDialog.setCancelable(true);
            twsbiSelectionMenuDialog.setCanceledOnTouchOutside(true);
            
            // To Open new Canvas ===================================
            Button newLayoutButton = (Button) twsbiSelectionMenuDialog.findViewById(R.id.newLayoutButton);
            newLayoutButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    twsbiSelectionMenuDialog.dismiss();
                    // AlertDialog for confirmation
                    AlertDialog.Builder clearConfirmDialog = new AlertDialog.Builder(TWSBIDrawMainActivity.this);
                    clearConfirmDialog.setMessage("Do you want to clear this and open new canvas ?").setCancelable(false)
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // Action for 'Yes' Button
                            myView = new MyView(TWSBIDrawMainActivity.this);
                            takePhotoFromCamera = false;
                            takePhotoFromGallery = false;
                            canvasColor = 0xFFFFFFFF;
                            drawingLayout.removeView(myView);
                            drawingLayout.addView(myView);
                        }
                    })
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            //  Action for 'NO' Button
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = clearConfirmDialog.create();
                    alert.setTitle("Draw");
                    alert.setIcon(R.drawable.app_icon);
                    alert.show();
                }
            });
            
            // For canvas Color Selection ===================================
            Button canvasColorButton = (Button) twsbiSelectionMenuDialog.findViewById(R.id.canvasColorButton);
            canvasColorButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    twsbiSelectionMenuDialog.dismiss();
                    pickColour(); // to pick colour
                }
            });

只需引用您的情况即可,它会对您有所帮助。

关于android - 警报对话框生成器确认按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9125920/

相关文章:

android - 有没有办法防止 AlertDialog 因输入无效而关闭?

android - Jetpack 将数字输入输入到 TextField

java - 为什么我无法隐藏我的单选 AlertDialog?

java - 警报对话框不起作用

android - ViewPager 内 fragment 的按钮在错误引用时触发 onClickListener

android - 未显示警报对话标题和消息

android - 将 AlertDialog 正按钮文本设置为粗体

android - 点击监听器上的搜索栏拇指

android - 在 Android HCI 日志中发现的 BLE GATT 服务的不完整列表在 getServices() 中返回

java - Android 应用程序和服务器应该多久同步一次