Question

I'm using shouldoverrideurlloading to trigger a function when a link is clicked in my webview. Is their a way to stop the webview from loading a new screen when the link is clicked. All I want to do is run the function NetworkOperations.addlike(url) when a user clicks the link not load a new page in webview

EX:

 public boolean shouldOverrideUrlLoading(WebView view, String url)
        {

            if (url.endsWith("&like"))
            {

                NetworkOperations.addlike(url);
                Break;

            }
         }
Was it helpful?

Solution

If you return true it should NOT load the url in the WebView, while false will let the WebView load the page.

public boolean shouldOverrideUrlLoading(WebView view, String url) {
  if (url.endsWith("&like")) {
    NetworkOperations.addlike(url);
    return false;
  } else {
    return true;
  }
}

Android Documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top