Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid multiple WebViews Issue: Not being able to load the first one until the rest have loaded
    primarykey
    data
    text
    <p>I have an activity that stores 5 <code>WebViews</code> in a <code>ViewFlipper</code>. It only shows one at a time. In the onCreate() of my activity I'm loading the first WebView on my main thread and the others in a background thread.</p> <p>What I was expecting was to see the <code>WebView</code> right away while the others were still loading. What I found is that the first <code>WebView</code> i perform a <code>loadData()</code> with finishes last. I found this by setting a <code>WebChromClient</code> and checking the <code>onProgressChanged()</code>. The first WebView always seems to load last. </p> <p>I'm assuming the WebView.loadData() function works asynchronously, but I have no idea why the first one I load always finishes last, not ever 2nd, 3rd, 4th or 1st, but 5th, which is last in my case.</p> <p>Does anyone know why?</p> <p>Here's some example code:</p> <p>Setting up my WebViews</p> <pre><code>for( int i = 0; i &lt; 5; i++ ){ WebView tempWebView = new WebView(this); tempWebView.setWebChromeClient( new MyWebChromClient( i ) ); mFlipper.addView(tempWebView); } ( (WebView)mFlipper.getChildAt(0) ).loadData( content, "text/html", "UTF-8" ); // load the others now in a background thread... </code></pre> <p>Here's my WebChromClient</p> <pre><code>private class MyWebChromClient extends WebChromeClient{ private int webViewId; public MyWebChromClient( int viewFlipperChildNum ){ webViewId = viewFlipperChildNum; } public void onProgressChanged(WebView view, int newProgress) { if( newProgress == 100 ) Log.i("ChromClient", "WebView Id: " + webViewId + "Progress changed: " + newProgress ); }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload