1

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..=

4

2 回答 2

1

您不能重复使用相同的警报对话框

 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();
于 2012-12-24T07:19:33.443 回答
1
DialogInterface.OnClickListener dialogClickListener = new  DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which){
    case DialogInterface.BUTTON_POSITIVE:
        //Yes button clicked
        break;

    case DialogInterface.BUTTON_NEGATIVE:
        //No button clicked
        break;
    }
}
};

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();

如果您有其他是/否框,您还可以重用该 DialogInterface.OnClickListener

于 2012-12-24T05:47:43.053 回答