Ok, so I was able to set my own "OnClickListener" for TextView links. My solution was to copy Linkify into 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 the new field that I set before using the new CustomLinkify .
I know that this is not a very elegant solution, and I prefer google to allow the installation of the listener through the native Linkify, but for me it is better than implementing my own Spannable logics (as suggested in other related questions).
I believe in Linkify code, and I think that from time to time I will check if any changes will be made to it, if so, of course, I will update CustomLinkify with the changes.
Hope this helps someone.
source share