divyenduz
divyenduz

Reputation: 2027

How to change the title of a AlertDialog.Builder after it is shown?

I want to implement a in app browser in my app. To achive that I used a WebView inside a AlertDialog.Builder object and displayed it.

final AlertDialog.Builder alert = new AlertDialog.Builder(context);

Now I had a problem, I wanted the title of the AlertDialog.Builder to show the progress of the page that is loaded, so I Override the onProgressChanged function and tried to reset the title as follows:

wv.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress) {
        alert.setTitle("Loading..." + progress + "%");
    tv.setText("Loading..." + progress + "%");
    view.setVisibility(View.GONE);
    if (progress == 100) {
        alert.setTitle(title);// THIS DOES NOT HAVE ANY EFFECT
        tv.setVisibility(View.GONE);//THIS IS "LOADING..." string, That I have written as make shift for the time being
        view.setVisibility(View.VISIBLE);//This displays the WebView when it if loaded.
    }
}
});

I want the AlertDialog.Builder title to change dynamically.

Upvotes: 4

Views: 3625

Answers (1)

jspurlock
jspurlock

Reputation: 1476

The builder is only used to create the AlertDialog instance the first time. Get a handle to the dialog instance using AlertDialog.create before showing, you can then set the title on that.

Upvotes: 6

Related Questions