Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

: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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...