سؤال

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