Refresh or change the AlertDialog Message

Agreed with android developer. You can also use

TextView messageView = (TextView) alert.findViewById(android.R.id.message);

To get the control over the messageTextView of AlertDialog. Then you can set the new text there.


Use alert.setMessage() instead of builder.setMessage(). Call alert.setMessage() and set message of your dialog anytime you want.

Example:

     AlertDialog.Builder dialogBuilder;
     AlertDialog alertDialog;

     @Override
     protected void onCreate(Bundle savedInstanceState)
     {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       dialogBuilder = new AlertDialog.Builder(MainActivity.this);
       alertDialog = dialogBuilder.create();
     }


     public void showAlert(int caller) {
       if(alertDialog != null && !alertDialog.isShowing()) {
        switch (caller){
            case 1:
                alertDialog.setMessage("First method call");
                break;
            case 2:
                alertDialog.setMessage("Second method call");
                break;
            case 3:
                alertDialog.setMessage("Third method call");
                break;
            }
            alertDialog.show();
         }
      }

Yes ,you can.

For example, if you create your own dialog, with your own layout, you can set an id for each of the views, and then access each of them (for example the textView) and set its new text whenever you wish to.