gowri
gowri

Reputation: 681

Can alert dialog changes the title at Runtime in android

In Android, can I change the title of a dialog box at Runtime?

AlertDialog.Builder builder;
builder = new AlertDialog.Builder(Manage_Holidays.this);
builder.setMessage("Are you sure you want to insert new holiday")
.setCancelable(false)
.setTitle("Confirmation")
.setNegativeButton("No",new DialogInterface.OnClickListener() {
    public void onClick(    DialogInterface dialog,int id) {
                   // Title need to changed ass progress                            }})
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
    public void onClick(    DialogInterface dialog,int id) {
    builder.setMessage("Processing...");
    builder.setTitle("dsjc");
    }}).setCancelable(false);
 AlertDialog alert = builder.create();
 alert.show();

In this, I thought to display a string on clicking yes button and another string for no button..=

Upvotes: 1

Views: 1721

Answers (1)

KMI
KMI

Reputation: 506

You cannot reuse the same alert dialog

 final AlertDialog.Builder builder,anotherbuilder;
     builder = new AlertDialog.Builder(MainView.this);
     anotherbuilder =new AlertDialog.Builder(this);
     builder.setMessage("Are you sure you want to insert new holiday")
     .setCancelable(false)
     .setTitle("Confirmation")
     .setNegativeButton("No",new DialogInterface.OnClickListener() {
         public void onClick(    DialogInterface dialog,int id) {
                        // Title need to changed ass progress                   
             }})
     .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
         public void onClick(    DialogInterface dialog,int id) {
         anotherbuilder.setMessage("Processing...");
         anotherbuilder.setTitle("dsjc");
         AlertDialog alert = anotherbuilder.create();
          alert.show();
         }}).setCancelable(false);


      AlertDialog alert = builder.create();
      alert.show();

Upvotes: 1

Related Questions