Reputation: 388
how can I wait to show the webView until it loads all the web data? i have created this asynktask sketch:
@Override
protected Void doInBackground(String... params) {
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
String url = params[0];
webView.loadUrl(url);
return null;
}
@Override
protected void onPreExecute() {
//progress = ProgressDialog.show(MainActivity.this,"wait","downloading URL");
progressBar.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Void result) {
webView.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
}
}
it works but a the end of this code, after onPostExecute i'm still seeing the blank page of webview loading
Upvotes: 0
Views: 356
Reputation: 6622
loadUrl
is already doing everything asynchronously, so onPostExecute is called right away.
If you want to display a loading indicator, you need to use that :
mWebView.setWebViewClient(new WebViewClient() {
public void onPageStarted (WebView view, String url, Bitmap favicon) {
view.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
}
public void onPageFinished(WebView view, String url) {
view.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
}
});
webView.loadUrl(url);
and of course remove you AsyncTask.
More : here
Upvotes: 1