机器人的WebView [英] Android WebView

查看:146
本文介绍了机器人的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过参照本的WebView 教程,特别是这种方法

With reference to this WebView tutorial, in particular this method

private void setupWebView(){
    String MAP_URL = "http://gmaps-samples.googlecode.com/svn/trunk/articles-android-webmap/simple-android-map.html";
    String centerURL = "javascript:centerAt(" + mostRecentLocation.getLatitude() + ","+ mostRecentLocation.getLongitude()+ ")";
    webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    //Wait for the page to load then send the location information
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public void onPageFinished(WebView view, String url){
            webView.loadUrl(centerURL);
        }
    });
    webView.loadUrl(MAP_URL);
}

我发现,如果我把 webView.loadUrl(centerURL); 后直接 webView.loadUrl(MAP_URL); 像这样

private void setupWebView(){
    String MAP_URL = "http://gmaps-samples.googlecode.com/svn/trunk/articles-android-webmap/simple-android-map.html";
    String centerURL = "javascript:centerAt(" + mostRecentLocation.getLatitude() + "," + mostRecentLocation.getLongitude()+ ")";
    webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    //Wait for the page to load then send the location information
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public void onPageFinished(WebView view, String url){
            //DO NOTHING
        }
    });
    webView.loadUrl(MAP_URL);
    webView.loadUrl(centerURL);
}

它不再起作用。因此, centreAt(..) JavaScript方法包含的int MAP_URL

it no longer works. So the centreAt(..) javascript method is contained int the MAP_URL.

我不知道是否实际上已被加载的网址在 webView.loadUrl(..)方法返回。 它看起来是这样,因为上面的方法等待其运行的JavaScript之前完全加载

I'm wondering if the webView.loadUrl(..) method returns before the url has actually been loaded. It looks that way since the top method waits for it to load fully before running the javascript

推荐答案

webView.loadUrl()是异步的:它会立即返回,并不断的WebView在它自己的工作主题。

Yes, webView.loadUrl() is asynchronous: it returns immediately and WebView keeps working in it's own thread.

要监视的WebView页面加载使用<一个href="http://developer.android.com/reference/android/webkit/WebViewClient.html#onPageFinished%28android.webkit.WebView,%20java.lang.String%29"><$c$c>WebViewClient.onPageFinished(..):

To monitor WebView page loading use WebViewClient.onPageFinished(..):

webview.setWebViewClient(new WebViewClient() {
    public void onPageFinished(WebView view, String url) {
        // do something here
    }
});

这篇关于机器人的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆