YemYem
YemYem

Reputation: 11

Refreshing a page in a WebView android

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.

Upvotes: 0

Views: 2666

Answers (1)

YemYem
YemYem

Reputation: 11

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 :)

Upvotes: 1

Related Questions