How to test if a textview contains a specific link?

1.1k Views Asked by At

I have a textview with link included as an a tag. In string.xml I have string like this - This is my text view with <a href="url">link</a>

I want to programmatically check whether textview has this link and whether it is clickable. If I try using textview.getText().toString() it will convert html to plain text (not raw html) and remove all the links.

Is there any way I can check this? The second part is, I can manually verify that the link is clickable, but I want to programmatically verify whether the link is working. How do I do that?

1

There are 1 best solutions below

0
On

Thanks to @Andy

textview.getUrls() gets you the spannable URLs in the text view - so in your example it would return an array of length 1 and [0].getUrl() would return "url".

((TextView) v).getUrls()[0].getURL()