3

I have a simple helloworld app. I am trying to tell the Activity that a user clicked, "Cnn.com"

    WebViewClient wc = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.equals("http://cnn.com/")) {
                //TELL ACTIVITY CNN WAS CLICKED
                return true;
            } else {
                return false;

            }
        }

    };

    mWebView.setWebViewClient(wc);

How would I do this.

(I am coming from a C# .NET background)

Ian Vink
  • 66,960
  • 104
  • 341
  • 555
  • how exactly you want tell the activity that? You want to show a dialog? you want to open another activity? you want to show a Toast? – Cristian Jul 14 '10 at 21:09

1 Answers1

3
public class YourActivity extends Activity{

    // bla bla bla

    // the code you already have
    WebViewClient wc = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.equals("http://cnn.com/")) {
                YourActivity.this.tellMe();
                return true;
            } else {
                return false;

            }
        }

    };

    // this is the method to 'tell' the activity that someone clicked the link
    public void tellMe(){
        // in this case I just raise a toast.
        // but you can do whatever you want here ;)
        Toast.makeText(YourActivity.this, "eyy!! somebody clicked the cnn link", 1).show();
    }
}
Cristian
  • 198,401
  • 62
  • 356
  • 264