编辑:推特片段

时间:2014-05-08 05:43:21

标签: android android-fragments android-webview android-twitter

我需要在我的Android应用程序中的片段上显示一个推特列表(Link),但我不知道如何在片段中包含MyWebViewClient活动..请帮助。

    public class TwitterFragment extends Fragment {
        private WebView webview;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_twitter, container, false);
        String url = "https://twitter.com/Almounir/lists/intersante";

        webview = (WebView) rootView.findViewById(R.id.myWebView);
        //next line explained below
        webview.setWebViewClient(new MyWebViewClient(this));
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(url);

        public MyWebViewClient() {
            super();
            //start anything you need to
         }

         public void onPageStarted(WebView view, String url, Bitmap favicon) {
            //Do something to the urls, views, etc.
         }
        return rootView;
    }
} 

1 个答案:

答案 0 :(得分:0)

我用一个简单的WebView回答了我的问题:

public class TwitterFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_twitter, container, false);

        WebView wv = (WebView)rootView.findViewById(R.id.WebView);

        String url = "https://www.google.com";
        wv.loadUrl(url);
        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

        return rootView;
    }
}

ThanK You !!!