WebView Back, Refresh, Forward? It just doesn't work!

I tried everything to make the "forward" and "back" work.

Refresh works [I figured this out by changing the reading method to 'webView.reload ();' instead of 'webView.refresh ();'

Can someone help with forward and back? I tried forward, canGoForward and goForward, as well as back, canGoBack and goBack. There are no error codes, but none of these methods does anything.

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu); // Add menu items, second value is the id, use this in the onCreateOptionsMenu
    menu.add(0, 1, 0, "Back");
    menu.add(0, 2, 0, "Refresh");
    menu.add(0, 3, 0, "Forward");
    return true; // End of menu configuration
}
public boolean onOptionsItemSelected(MenuItem item){ // Called when you tap a menu item
    switch (item.getItemId()){
        case 1: //If the ID equals 1, go back
            webView.goBack();
        return true;
        case 2 : //If the ID equals 2, refresh
            webView.reload();
        return true;
        case 3: //If the ID equals 3, go forward
            webView.goForward();
        return true;
        }
    return false;
    }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) { // Enables browsing to previous pages with the hardware back button
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) { // Check if the key event was the BACK key and if there history
        webView.goBack();
        return true;
    }   // If it wasn't the BACK key or there no web page history, bubble up to the default
        // system behavior (probably exit the activity)
    return super.onKeyDown(keyCode, event);
}

}

+5
source share
1 answer

, , , - URL-. , .

, webview - , . , webview ? :

webview = new WebView(this);
webview.loadUrl("http://slashdot.org/");

, , "webView" loadUrl , URL-. , webview .

+4

All Articles