0

i'm working on an Android Application who use webview for displaying somes pages.

I've an action bar and an action tab bar. On the action bar i've 2 buttons, one open a login page and the second must refresh the current page in the webview.

Here is the code of the fragment where the webview is :

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View V = inflater.inflate(R.layout.main_screen, container, false);

    WebView webView = (WebView)V.findViewById(R.id.webView_main);

    WebSettings webSettings = webView.getSettings();

    webSettings.setJavaScriptEnabled(true);

    webView.setWebViewClient(new WebViewClient());

    switch (getArguments().getInt(ARG_SECTION_NUMBER)) {

        case 1:

            webView.loadUrl(homeURL);

            break;

        case 2:

            webView.loadUrl(url2);

            break;

        case 3:

            webView.loadUrl(url3);

            break;

        case 4:

            webView.loadUrl(url4);

            break;

        case 5:

            webView.loadUrl(url5);

            break;
    }   

    switch (getArguments().getInt(ARG_ACTIONBAR)) {

        case 1:

            webView.loadUrl(homeURL);

            break;

        case 2:

            webView.loadUrl(loginURL);

            break;

        case 3:

            webView.loadUrl("javascript:window.location.reload(true)");

            break;

        case 4:

            webView.loadUrl(helpURL);

            break;

        case 5:

            webView.loadUrl(testJSURL);

            break;
    }

    return V;
}

As you can see, i use javascript for refresh but it doesn't work, that's only load a blank page. I've tried to store the current URL in a string and just load this string when the user clic on the refresh but it doesn't work too ...

If someone have an idea ? :)

PS : The app have permission for internet, and the javascript is activated.

HaemEternal
  • 2,229
  • 6
  • 31
  • 50
YemYem
  • 11
  • 1
  • 3
  • Can you hardcode the URLs to google.com to check? – Reno Jan 22 '13 at 11:27
  • I've hardcode some URL for the test, all of my tabs load the url, but the refresh doesn't work. I've hardcode an url for testing if the activation of JS work and it works, but not the refresh ^^ – YemYem Jan 22 '13 at 12:28

1 Answers1

1

Ok i found the solution.

I've put the action bar management inside my fragment class instead of the activity class, so it works and my app is more clear now :)

YemYem
  • 11
  • 1
  • 3
  • i have similar , can you explain what you did ? http://stackoverflow.com/questions/41214792/refresh-webview-if-external-page-closed – Dr.Mezo Dec 19 '16 at 01:53