尝试在 TabbedActivity 的第二个选项卡中添加 webview

Trying to add a webview in the second tab of a TabbedActivity

我正在尝试完成此操作但没有成功。目前代码给出错误,因为缺少 return 语句。

我的方法也可能有问题。

我们将不胜感激。

public class TipsTabFragment extends Fragment {

private WebView wv1;

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

    String url = "http://example.com";


    RelativeLayout view = null;
    wv1 = (WebView) view.findViewById(R.id.wv1);
    LayoutInflater mInflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    wv1.loadUrl(url);
    wv1.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

}
}

您需要膨胀一个视图,return那个

public class TipsTabFragment extends Fragment {

private WebView wv1;

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

    String url = "http://example.com";



    View view = inflater.inflate(R.layout.some_layout, container, false);
    wv1 = (WebView) view.findViewById(R.id.wv1);
    wv1.loadUrl(url);
    wv1.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

 return view;
}
}