i have a TextView filled with text which i get from a server. I'm using Linkify for handling all the link searching and for setting a URLSpan where needed throughout its addLinks method.
The problem is that the default behavior when clicking a link is opening it in a browser, what i want is to get the clicked link and handle it my self.
I don't see any method of Linkify which let me set a "OnClick" or something...
Thank for your help :)
Ok so i finally managed to set my own "OnClickListener" to the TextView's links. My solution was to copy
Linkify
to my project, name itCustomLinkify
and just change itsapplyLink
method:From:
To:
Where
_onLinkClickListener
is a new field, set by me before using the newCustomLinkify
.I know its not a very elegant solution and i prefered google to allow setting a listener through the native Linkify, but, for me, this is better than implementing my own
Spannable
logics (as suggested in other related questions).I trust the
Linkify
code and i guess i'll check from time to time to see if any changes made on it, if so, i'll of course updateCustomLinkify
with the changes.Hope this will help someone.