I have a problem with WebView
, the design of my application uses Tabs and Navigation Drawer
, in the Tabs I have fragments that show content by webview
, the problem is that each that change of Tabs the webview
are updated again, is there any way to avoid it?
The image assumes that my content of the "Agreements" Tab was already loaded but when you return to that Tab it reloads as if it were the first time it opens.
This is the adapter code:
public class TabAdapter extends FragmentStatePagerAdapter {
private Context context;
public TabAdapter(FragmentManager manager, Context context) {
super(manager);
this.context = context;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0: return new BlogFragment();
case 1: return new ConveniosFragment();
case 2: return new FavoritosFragment();
}
return null;
}
@Override
public int getCount() {
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0: return context.getString(R.string.blog);
case 1: return context.getString(R.string.convenios);
case 2: return context.getString(R.string.favoritos);
}
return super.getPageTitle(position);
}
}
This is the code of ConveniosFragment();
public class ConveniosFragment extends Fragment {
private ProgressDialog progress;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//return inflater.inflate(R.layout.conveniosfragment, container, false);
View mainView = (View) inflater.inflate(R.layout.conveniosfragment, container, false);
WebView webView = (WebView)mainView.findViewById(R.id.viewConvenios);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setCacheMode( WebSettings.LOAD_CACHE_ELSE_NETWORK );
webView.getSettings().setAppCacheMaxSize (1024 * 1024 * 8 );
webView.canGoBack();
webView.goBack();
webView.loadUrl("http://seccion15.org.mx/convenios/");
progress = ProgressDialog.show(getContext(), "Espere...",
"Cargando contenido.", true);
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
if (progress != null)
progress.dismiss();
}
});
return mainView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onDetach() {
super.onDetach();
}
}