将webview添加到sherlock片段中

时间:2013-12-08 19:33:52

标签: android android-fragments android-webview android-logcat

我成功地将WebView添加到sherlock片段中。它运行正常但是当我看到我的logcat时,我发现了一个奇怪的输出:

12-08 19:08:49.360: I/Choreographer(1495): Skipped 44 frames!  The application may be doing too much work on its main thread.

它就像一个循环,不想停止!!

那些框架是什么?我该怎么办呢?

这是线程问题吗?

有我的代码,也许我正在制作错误,这就是我的logcat爆炸的原因

public class Schedule extends SherlockFragment {

    private WebView web_v;

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            // TODO Auto-generated method stub
        View v= inflater.inflate(R.layout.fragment_schedule, container, false);
        web_v=(WebView)v.findViewById(R.id.webView_schedule);
        WebSettings web_sett=web_v.getSettings();
        web_sett.setJavaScriptEnabled(true);
        web_v.setWebViewClient(new MyWebClient());
        web_v.loadUrl("http://www.pcinpact.com/?skipua=1");



        v.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // TODO Auto-generated method stub
                if(keyCode==KeyEvent.KEYCODE_BACK && web_v.canGoBack()){
                    web_v.goBack();
                    return true;
                }
                return false;
            }
        });
        return v;
        }

    private class MyWebClient extends WebViewClient{

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub
            web_v.loadUrl(url);
            return true;
        }


    }
}

提前感谢。

1 个答案:

答案 0 :(得分:1)

请删除对shouldOverrideUrlLoading内部对loadUrl()的调用,并从此函数返回false。

问题是你要回电告诉webview重新开始从头开始加载URL,从回调中告诉你WebView要加载URL,导致加载URL的请求循环