AlertDialog alertdialog机器人内部机器人、AlertDialog、alertdialog

2023-09-13 23:53:54 作者:来日无期

我想补充内alertdialog.But的alertdialog无法看到第二alertdialog..please帮我 在此显示我的code

  AlertDialog alertDialog =新AlertDialog.Builder(myclass.this).create();
alertDialog.setTitle(第一警报);
alertDialog.setMessage(第一个警报preSS);
alertDialog.setButton(确定,新DialogInterface.OnClickListener(){
    公共无效的onClick(DialogInterface对话,诠释它){
        //在这里你可以添加功能
        dialog.cancel();

        AlertDialog alertDialog1 =新AlertDialog.Builder(myclass.this).create();
        alertDialog1.setTitle(第二个警告对话框);
        alertDialog1.setMessage(第二个警告对话框的详细信息);
        alertDialog1.setButton(扫描另一,新DialogInterface.OnClickListener(){
                           公共无效的onClick(DialogInterface对话,诠释它){
}}); }
 

解决方案

这是会是一个迟到的答案,但你可以创建内部onClickListener一个AlertDialog就像这样:

 公共无效的onClick(DialogInterface对话,诠释它){
                                // TODO自动生成方法存根
                                如果(选项[这] ==管理){

                                }
                                其他 {
                                    dialog.dismiss();
                                    最后AlertDialog警报;

                                    AlertDialog.Builder dialog2 =新AlertDialog.Builder(CategoryPage.this);
                                    警报= dialog2.create();
                                    alert.setTitle(删除+标题+?);
                                    alert.setMessage(你确定要删除此类别?);

                                    alert.setButton(是,新DialogInterface.OnClickListener(){

                                        公共无效的onClick(DialogInterface对话,诠释它){
                                            // TODO自动生成方法存根
                                            Toast.makeText(CategoryPage.thisYESS,Toast.LENGTH_LONG).show();
                                        }
                                    });

                                    alert.setButton2(否,新DialogInterface.OnClickListener(){

                                        公共无效的onClick(DialogInterface对话,诠释它){
                                            // TODO自动生成方法存根
                                            alert.dismiss();
                                        }
                                    });

                                    alert.show();
                                }
                            }
                        });
 

对话框AlertDialog的使用

I am trying to add an alertdialog within an alertdialog.But not able to see the second alertdialog..please help me here is my code shown

AlertDialog alertDialog = new AlertDialog.Builder(myclass.this).create();
alertDialog.setTitle("First alert");
alertDialog.setMessage("first alert press");
alertDialog.setButton("ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        // here you can add functions
        dialog.cancel();

        AlertDialog alertDialog1 = new AlertDialog.Builder(myclass.this).create();
        alertDialog1.setTitle("second alert dialog");
        alertDialog1.setMessage("second alert dialog details");
        alertDialog1.setButton("Scan Another", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int which) {
}}); }

解决方案

It is gonna be a late answer but you can create an AlertDialog inside onClickListener just like this:

public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub
                                if (options[which] == "Manage") {

                                }
                                else {
                                    dialog.dismiss();
                                    final AlertDialog alert;

                                    AlertDialog.Builder dialog2 = new AlertDialog.Builder(CategoryPage.this);
                                    alert = dialog2.create();
                                    alert.setTitle("Delete " + title + "?");
                                    alert.setMessage("Are you sure you want to delete this category?");

                                    alert.setButton("Yes", new DialogInterface.OnClickListener() {

                                        public void onClick(DialogInterface dialog, int which) {
                                            // TODO Auto-generated method stub
                                            Toast.makeText(CategoryPage.this, "YESS", Toast.LENGTH_LONG).show();
                                        }
                                    });

                                    alert.setButton2("No", new DialogInterface.OnClickListener() {

                                        public void onClick(DialogInterface dialog, int which) {
                                            // TODO Auto-generated method stub
                                            alert.dismiss();
                                        }
                                    });

                                    alert.show();
                                }
                            }
                        });