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 it CustomLinkify
and just change its applyLink
method:
From:
private static final void applyLink(String url, int start, int end, Spannable text)
{
URLSpan span = new URLSpan(url);
text.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
To:
private static final void applyLink(final String url, int start, int end, Spannable text)
{
URLSpan span = new URLSpan(url)
{
@Override
public void onClick(View widget)
{
_onLinkClickListener.onLinkClicked(url);
}
};
text.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Where _onLinkClickListener
is a new field, set by me before using the new CustomLinkify
.
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 update CustomLinkify
with the changes.
Hope this will help someone.