Open mparyani445 opened 4 years ago
Don't think this issue is specific to this library, sorry.
Same. this works when using normal LinkMovementMethod but when using BetterLinkMovementMethod, it does not make it a link.
Huh, I wonder if my implementations of linkify*()
functions are wrong. I'd advise to avoid using them in that case.
Ok I have a solution for this, We have text with HTML, but also want the Linkify to work as well. I will open a PR soon for you. The issue is that when you call Linkify on a text view where you did Html.fromHtml, they clear the previous spans. So the solution is to first record the current spans, then apply linkify which will remove your HTML spans, then apply them back.
Basically update addLinks to this ` private static void addLinks(int linkifyMask, BetterLinkMovementMethod movementMethod, TextView textView) { textView.setMovementMethod(movementMethod); URLSpan[] htmlUrlSpans = null; if(textView.getText() instanceof SpannableString){ htmlUrlSpans = ((SpannableString)textView.getText()).getSpans(0, textView.getText().length(), URLSpan.class); }
SpannableString buffer = new SpannableString(textView.getText());
if (linkifyMask != LINKIFY_NONE) {
Linkify.addLinks(buffer, linkifyMask);
}
if(htmlUrlSpans != null && textView.getText() instanceof SpannableString){
for (URLSpan span : htmlUrlSpans) {
int end = ((SpannableString)textView.getText()).getSpanEnd(span);
int start = ((SpannableString)textView.getText()).getSpanStart(span);
buffer.setSpan(span, start,end,0);
}
}
textView.setText(buffer);
}`
The library is working fine only if we have link between tags for example: Some text http://www.google.com Some text http://www.google.com In this way it will highlight the link and clickable also, but in case 2
Some text Go to Google Some text Go to Google
Link is not generating neither it is clickable, can you provide any solution for this I have tried using 1.BetterLinkMovementMethod.linkify(Linkify.ALL, textview) and 2.BetterLinkMovementMethod.linkifyHtml(textview) both