1

I have an HTTP link in my layout: <string name="contact_us">Please <a href="mailto:SERVICES@some.com">email services</a> or call <a href="tel:4399999999">(408) 888-5555</a> for questions.</string>

And in my activity:

disclaimer = (TextView) view.findViewById(R.id.disclaimer);    
disclaimer.setMovementMethod(LinkMovementMethod.getInstance());

This works by opening a browser or the dial. But now I want to track some statistics before opening the links. Is there a way to "Listen" when this links are clicked?

Jose Gonzalez
  • 1,491
  • 3
  • 25
  • 51

1 Answers1

1

You can achieve this kind of task using SpannableString.. please check this below code :

SpannableString ss = new SpannableString("Android is a Software stack");
ClickableSpan clickableSpan = new ClickableSpan() {
    @Override
    public void onClick(View textView) {
        startActivity(new Intent(MyActivity.this, NextActivity.class));
    }
    @Override
    public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setUnderlineText(false);
        }
};
ss.setSpan(clickableSpan, 22, 27, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

TextView textView = (TextView) findViewById(R.id.hello);
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(Color.TRANSPARENT);

It will work for you. and please check this example.

Rujul Gandhi
  • 1,700
  • 13
  • 28