我希望能够在Fragment中保留Webview的状态。我的需求是,当我通过导航抽屉切换Fragment时,在我的Webview中保存状态。我找到了一些保存状态的代码,但我不知道在哪里写它。有人可以帮我吗?对于我的英语,我很抱歉。
这是保存状态的代码:
这是保存状态的代码:
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mWebView.saveState(outState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mWebView.restoreState(savedInstanceState);
}
这是我的代码
public class Zastupovanie extends SherlockFragment{
private Context context;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved){
View v = inflater.inflate(R.layout.zastupovanie, group, false);
final ProgressDialog pd = ProgressDialog.show(getActivity(), "", "Prosím čakajte. Prebieha načítavanie... ", true);
final WebView myWebView = (WebView) v.findViewById(R.id.zastupovanie2);
myWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
pd.dismiss();
}
});
myWebView.getSettings().setBuiltInZoomControls(false);
myWebView.getSettings().setSupportZoom(false);
myWebView.getSettings()
.setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setAllowFileAccess(true);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
myWebView
.loadUrl("http://soszm.edupage.org/substitution/?");
return v;
}
}