androidtextviewspannablestringautolinkclickablespan

Linkify.addLinks with Span not working


I have textview with autoLink, but whenever i add custom span (ClickableSpan) to textview its auto link to web url and mobile number is not working. is there any easy way to solve this issue. Style is applied but click is not working.


Solution

  • https://stackoverflow.com/a/39494610/4639479 I used this answer and worked fine

    public static String[] extractLinks(String text) {
        List<String> links = new ArrayList<String>();
        Matcher m = Patterns.WEB_URL.matcher(text);
        while (m.find()) {
            String url = m.group();
            links.add(url);
        }
        return links.toArray(new String[links.size()]);
    }