1

我正在做我的android项目。我创建了带有“是”和“否”按钮的对话框。如果我单击“是”,则应显示一个新对话框,其中包含可供选择的选项。我创建了带有选项的对话框。但是当我在我首先创建的对话框中单击“是”时无法显示它。我该怎么做?请帮忙。谢谢。

这是我创建的对话框的代码。当我在此对话框中单击“是”按钮时,我应该显示另一个对话框

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Low Memory\nYou want to send the file to server?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {

                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        finish();
                   }
               });
AlertDialog alert = builder.create();
alert.show();
4

3 回答 3

4
AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Low Memory\nYou want to send the file to server?")
            .setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    AlertDialog.Builder builder2 = new AlertDialog.Builder(CLASSNAME.this);
                    builder2.setTitle("hi!");
                    //etc
                    builder2.show();

                }
            })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                     dialog.cancel();
                     finish();
                }
            });
     AlertDialog alert = builder.create();
     alert.show();

希望这可以帮助。;)

于 2012-04-04T15:14:10.643 回答
0

试试这个代码:

 AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
        builder1.setMessage("Are you absolutely positively sure?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {

                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        finish();
                   }
               });
        final AlertDialog alert1 = builder1.create();




        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Low Memory\nYou want to send the file to server?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       alert1.show();
                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        finish();
                   }
               });
        AlertDialog alert = builder.create();
        alert.show();
于 2012-04-04T15:16:42.833 回答
0

看看这个

AlertDialog alertDialog1,alertDialog2;

     public  void  showAlertDialog1(String title,String message,final Context context)
            {
             alertDialog1 = new AlertDialog.Builder(context).create();
             alertDialog1.setTitle(title);
             alertDialog1.setMessage(message);
             alertDialog1.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                  errorAlertDialog2("second AlertDialog","second AlertDialog",context)

                }
             });
             alertDialog1.show();
            }




         public  void  showAlertDialog2(String title,String message,Context context)
            {
             alertDialog2 = new AlertDialog.Builder(context).create();
             alertDialog2.setTitle(title);
             alertDialog2.setMessage(message);
             alertDialog2.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                  alertDialog2.dismiss();
                }
             });
             alertDialog2.show();
            }
于 2012-04-04T15:35:55.213 回答