Alex Rivera | Logout

How to listen for a WebView finishing loading a URL?

Asked 2010-06-30T12:28:26.567
513

I have a WebView that is loading a page from the Internet. I want to show a ProgressBar until the loading is complete.

How do I listen for the completion of page loading of a WebView?

Edit
Report

1 Answer

5

You can trace the Progress Staus by the getProgress method in webview class.

Initialize the progress status

private int mProgressStatus = 0;

then the AsyncTask for loading like this:

private class Task_News_ArticleView extends AsyncTask<Void, Void, Void> {
    private final ProgressDialog dialog = new ProgressDialog(
            your_class.this);

    // can use UI thread here
    protected void onPreExecute() {
        this.dialog.setMessage("Loading...");
        this.dialog.setCancelable(false);
        this.dialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        try {
            while (mProgressStatus < 100) {
                mProgressStatus = webview.getProgress();

            }
        } catch (Exception e) {

        }
        return null;

    }

    protected void onPostExecute(Void result) {
        if (this.dialog.isShowing()) {
            this.dialog.dismiss();
        }
    }
}
answered 2010-06-30T12:48:22.877

Your Answer