Java – onpagefinished cannot be triggered correctly when rendering web pages
•
Java
For some reason, onpagefinished is triggering before WebView loading is complete - I can't figure out why
public class WebViewClientTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final WebView webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view,String url) {
super.onPageFinished(webview,url);
webview.scrollTo(0,500);
}
});
webview.loadUrl("http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=lala");
}
}
webView.loadDataWithBaseURL("fake://fake.com/",htmlBody,"text/html","utf-8",null);
Solution
I have a project that needs to run code only after the WebView displays the content. Like you, onpagefinished () doesn't work It launches too fast before the page is actually rendered@ H_ 301_ 4@ instead, I have to use a "picturelistener", which is triggered when the WebView actually updates the screen
mWebView.setPictureListener(new MyPictureListener());
//... and then later on....
class MyPictureListener implements PictureListener {
@Override
public void onNewPicture(WebView view,Picture arg1) {
// put code here that needs to run when the page has finished loading and
// a new "picture" is on the webview.
}
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
