Reputation: 543
I have a custom implementation of WebViewClient
that overrides onPageFinished()
, where I swap my loading view with the WebView
. Sometimes everything works great, but other times onPageFinished()
doesn't get called at all. It's completely random.
onPageStarted()
always gets called.
public class LoaderWebViewClient extends WebViewClient {
private final TableLayout swapTableLayout;
public LoaderWebViewClient(TableLayout swapTableLayout) {
this.swapTableLayout = swapTableLayout;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
// Sometimes doesn't get called
@Override
public void onPageFinished(WebView view, String url) {
swapTableLayout.removeAllViews();
swapTableLayout.addView(view);
super.onPageFinished(view, url);
}
}
I am instantiating a WebView
from a custom class:
WebView webView = new WebView(context);
WebViewClient webViewClient = new LoaderWebViewClient(swapTableLayout);
webView.setWebViewClient(webViewClient);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webView.loadUrl(url);
Upvotes: 0
Views: 993
Reputation: 543
I have found the problem. In onPageFinished()
I am removing all the views from the layout inside which the WebView
itself would reside (as seen in the next line).
And that somehow disrupts the loading of the WebView
. I have just replaced removing and reinserting views with hiding and showing them (they are always inflated in the layout) and everything seems to work fine.
Upvotes: 0