Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog inside alertdialog android

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) {
}}); }
like image 329
nikhilkilivayil Avatar asked Sep 28 '11 07:09

nikhilkilivayil


1 Answers

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) {
    if (options[which] == "Manage") {
      //Do smtg
    } 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();
    }
}
like image 128
Serdar S. Avatar answered Sep 26 '22 02:09

Serdar S.