0

Can I in anyway change the name of the link in android using Linkify? I have a description field which may contain phone number. I want to replace the phone number with "show phone number" text and when user clicks on it the phone number should appear.

E.G "selling audi for 30000 , contact 0300001--23323" becomes "selling audi for 30000 , contact show phone number"

  • I think it's been answered here [Android: Linkify TextView](https://stackoverflow.com/a/5794563/5933012) – NIKHIL MAURYA Oct 25 '18 at 11:40
  • no, my problem is different. phone numbers are dynamic and I need to change the text of the phone numbers,make it clickable . I have seen that link already – Uzair Aslam Oct 25 '18 at 11:45

1 Answers1

0

Then go with some custom implementation, most basic would be to use two TextViews one with mobile number which is clickable and change its text and appearnace on click. Another implementation could be use ClickableSpan on SpannableString

SpannableString ss = new SpannableString("selling audi for 30000 , contact show phone number");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
    //here you can change the phone number
}
@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);
NIKHIL MAURYA
  • 289
  • 1
  • 15