我正在努力实现这一目标,但没有成功。目前,代码提供错误作为缺少的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;
}
});
}
}
答案 0 :(得分:1)
你需要给视图充气并返回那个视图
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;
}
}