Switch Webview fragments by Navigation Drawer just like View pager

Published

I Have multiple fragments all containing webviews, I am switching fragments with a navigation drawer~
However whenever I go to another fragment and comes back to previous, it reloads.
I have tried many answers but none of them is working..

I don’t understand how to or where to apply (this code)
Switching between webview fragments to make it work.

I want to keep state of fragments as in view pager but I have navigation drawer..
Please help..

public class Google extends Fragment{ Context context;
private WebView myWebView

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    myWebView.saveState(outState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    myWebView.restoreState(savedInstanceState);
}

@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(),  "", "Please wait... ", true);

    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("https://google.com ");

    return v;
    }

}

Source: Android Questions

Published
Categorized as android, android-fragments, android-webview, fragment, java

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq