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;

            }
         }
有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top