我正在尝试在片段中实现WebView,它将引用我在XML中为片段创建的WebView元素,但是我收到错误(无法解析方法' findViewById(Int)' )我将如何使这项工作?
public class location_Fragment extends Fragment {
private WebView webView;
View rootview;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.location_layout, container, false);
return rootview;
View view = inflater.inflate(R.layout.location_layout, container, false);
webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("URL HERE");
return webView;
}
}
答案 0 :(得分:2)
将您的代码更改为以下
rootview = inflater.inflate(R.layout.location_layout, container, false);
webView = (WebView)rootview.findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("URL HERE");
return rootview;
}