Question

I can't figure out how to use Linkify for my TextView. I'm currently trying:

Linkify.addLinks(myTextView, Pattern.compile("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"), "http://");

I am using this post for my regex, which checks out here.

Am I missing something that I have to do in order to have URLs in my TextView clickable?

Essentially, I am hoping to have my TextView show my URLs as clickable links and actually click through, just like iOS's UITextViews are able to by changing the dataDetectorTypes property to match the proper UIDataDetectorType.

Was it helpful?

Solution 2

If you want to use Linkfy there should be no need to write an own regex pattern for web urls, just use

 Linkify.addLinks(text, Linkify.WEB_URLS);

OTHER TIPS

Use android:autoLink="web" in your layout XML for the TextView to handle http/https.

If you wish to continue using Linkify, be sure to do this after you have set the text in the TextView, not before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top