4

Is there a way how to remove "linkification" that was done by Linkify.addLinks(myEditText, Linkify.WEB_URLS);?

It should be disabled by Linkify.addLinks(myEditText, 0);, but it doesn't affect the linkified text at all. Even using myEditText.setLinksClickable(false); has absolutely no effect (links are still clickable).

The only solution I have come up with is a little hacky:

myEditText.setText(myEditText.getText().toString());

Quark
  • 1,578
  • 2
  • 19
  • 34

1 Answers1

4

It should be disabled by Linkify.addLinks(myEditText, 0);

Given that the method name begins with "add", I am not surprised that it leaves existing stuff intact.

Is there a way how to remove "linkification" that was done by Linkify.addLinks(myEditText, Linkify.WEB_URLS);?

You can try to find and remove all URLSpan (or perhaps ClickableSpan) objects from the Spannable:

Spannable stuff=myEditText.getText();
URLSpan[] spans=stuff.getSpans(0, stuff.length(), URLSpan.class);

for (URLSpan span : spans) {
  stuff.removeSpan(span);
}

// *maybe* need myEditText.setText(stuff), not sure
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Yes, this code works and "myEditText.setText(stuff)" is not necessary. Thanks! – Quark Mar 21 '15 at 13:35
  • @Tron: Ah, good. I wasn't sure if `getText()` returned the "live" object that was being edited or a copy, and if it was a copy, you'd need the `setText()` part. Glad it is working for you! – CommonsWare Mar 21 '15 at 13:38