0

I'm a bit new to Android programming so bear with me if I'm not 100% correct on how i phrase my questions. I'm looking for an a way to stop and reload my Android webView. The webView takes the user to a a simple HTML link, which works. Now I want to implement stop, reload, forward, and back buttons for the webView. What I did for the back and forward functions was very simple-- I simply created an onKeyDown function to facilitate going forward and backward as shown below:

public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack())
    {
        mWebView.goBack();
        return true;
    }

    if((keyCode == KeyEvent.KEYCODE_FORWARD) && mWebView.canGoForward())
    {
        mWebView.goForward();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

Now for reloading (refreshing) this webView and stopping this webView from loading is my trouble. I know for reloading a webView you could simply create a new setOnClickListener function and reload the URL. I'm not so sure about stopping a webView from loading. Do I have to create individual buttons for reloading/stopping the webView? Or is there a prebuilt function I can place inside my code that can help me do so? Any help would be appreciated! Thanks!

user200081
  • 563
  • 2
  • 12
  • 24
  • Check out the similar post http://stackoverflow.com/questions/6211473/webview-back-refresh-forward-simply-doesnt-work – GrIsHu Jan 09 '13 at 08:05

2 Answers2

1

Reload

mWebview.loadUrl("http://twitter.com"); //calling again `loadUrl()` with `url` gives your refresh type effects. 

I think there ain't any method like reloadUrl.

Stop Loading

stopLoading (): Stops the current load.

mWebView.stopLoading();
Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
  • Thanks! This is great. Just wondering--would I have to create individual buttons that you'd have to click for Android to refresh or stop a page? Or is there something prebuilt, similar to onKeyDown as shown above that could do it for me? – user200081 Jan 09 '13 at 08:37
  • I'm afraid but there isn't any pre-built button or something like that. So you have to individual create those button. – Vikalp Patel Jan 09 '13 at 08:46
0

Reloading the WebView

mWebView.reload();

Stop loading URL

mWebView.stopLoading ()

it will 100% work