urlspan

android custom URLSpan not working

試著忘記壹切 提交于 2019-12-23 04:15:52
问题 The problem is to handle my own action on click on URL span. I wrote custom URLSpan but it doesn't work. This is my custom URLSpan: public class CustomURLSpan extends android.text.style.URLSpan { private Command mClickAction; public CustomURLSpan(String url, Command clickAction) { super(url); mClickAction = clickAction; } @Override public void onClick(View widget) { try { mClickAction.execute(); } catch (Exception e) { } } public static void clickifyTextView(TextView tv, Command clickAction)

Handle clicks on TextView's links while using Linkify for finding and setting the links inside the text

冷暖自知 提交于 2019-12-21 12:26:03
问题 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 :) 回答1: Ok so i finally managed to set my own

android custom URLSpan not working

巧了我就是萌 提交于 2019-12-06 19:24:25
The problem is to handle my own action on click on URL span. I wrote custom URLSpan but it doesn't work. This is my custom URLSpan: public class CustomURLSpan extends android.text.style.URLSpan { private Command mClickAction; public CustomURLSpan(String url, Command clickAction) { super(url); mClickAction = clickAction; } @Override public void onClick(View widget) { try { mClickAction.execute(); } catch (Exception e) { } } public static void clickifyTextView(TextView tv, Command clickAction) { SpannableString current = new SpannableString(tv.getText()); URLSpan[] spans = current.getSpans(0,