当我们像这样在片段中加载 Webview 时:
private WebView viewer = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
viewer = (WebView) inflater
.inflate(R.layout.tut_view, container, false);
return viewer;
}
public void updateUrl(String newUrl) {
if (viewer != null) {
viewer.loadUrl(newUrl);
}
}
但我想使用线性布局而不是 webview。我试试这个,但错误出来了。
private LinearLayout viewer ;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
viewer = (LinearLayout) inflater.inflate(R.layout.tut_view, container, false);
View fragment = inflater.inflate(R.layout.tut_view, null);
return viewer;
}
public void updateUrl(String newUrl) {
if (viewer != null) {
}
}