Pregunta

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;

            }
         }
¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top