Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i make my progress dialog dismiss after webview is loaded?

What do I need to my code to make the dialog dismiss() after the webview is loaded?

public void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.main); 
            CookieSyncManager.createInstance(this);
            CookieSyncManager.getInstance().startSync();
            webview = (WebView) findViewById(R.id.webview);
            webview.setWebViewClient(new homeClient());
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setPluginsEnabled(true);
            webview.loadUrl("http://google.com");

            ProgressDialog pd = ProgressDialog.show(Home.this, "", 
                    "Loading. Please wait...", true);

        }

I've tried

public void onPageFinshed(WebView view, String url){
        pd.dismiss();
    }

Didn't work.

like image 905
brybam Avatar asked Jul 19 '10 18:07

brybam


People also ask

How do you override a WebView?

If you want to override certain methods, you have to create a custom WebView class which extends WebView . Also, when you are inflating the WebView , make sure you are casting it to the correct type which is CustomWebView . CustomWebView webView = (CustomWebView) findViewById(R. id.

What can I use instead of progress dialog?

"Deprecated" refers to functions or elements that are in the process of being replaced by newer ones. ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar , which can be embedded in your app's UI.

What is progress dialog in Android?

Android ProgressDialog is a dialog box/dialog window which shows the progress of a task. Android Progress Dialog is almost same as ProgressBar with the exception that this is displayed as a dialog box. In order to create a ProgressDialog to display a ProgressBar we need to instantiate it like this.


2 Answers

:o webview.setWebViewClient(new homeClient()); homeClient()????

try this

...
...
...

webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {              
                view.loadUrl(url);
                return true;
            }


          public void onPageFinished(WebView view, String url) {
                if (progressBar.isShowing()) {
                    progressBar.dismiss();
                }
            }
 webview.loadUrl("http://www.google.com");

}

Update:: this is a good example.

Android WebView and the Indeterminant Progress Solution

like image 168
Jorgesys Avatar answered Oct 04 '22 16:10

Jorgesys


This is OK.

public class WordActivity extends Activity {

    private WebView webview;
    private ProgressDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);
        Bundle objetbunble  = this.getIntent().getExtras(); 
        webview = (WebView) findViewById(R.id.webview);

        final Activity activity = this;

        webview.getSettings().setJavaScriptEnabled(true);

        webview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {              
                view.loadUrl(url);
                return true;
            }
            public void onLoadResource (WebView view, String url) {
                if (progressDialog == null) {
                    progressDialog = new ProgressDialog(activity);
                    progressDialog.setMessage("Chargement en cours");
                    progressDialog.show();
                }
            }
            public void onPageFinished(WebView view, String url) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog = null;
                }
            }
        }); 
        webview.loadUrl("http://www.example.com");
    }


}
like image 43
Samuel De Backer Avatar answered Oct 04 '22 15:10

Samuel De Backer