我試圖在單擊時啓動活動的文本字符串中生成可單擊的鏈接。我已經使用Linkify()來檢測我的文本中的鏈接。此功能可以添加文本鏈接,但只能添加網址。我需要將我的輸出轉換爲ClickableSpan,以便我可以實現this technique。將SpannableString轉換爲ClickableSpan
如何讓Linkify()的已識別鏈接變爲指向活動的ClickableSpans?
下面是我的代碼已經在Linkify使用:
// Linkify parameters
final static Pattern pattern = Pattern.compile("\\[[^]]*]"); // defines the fact that links are bound by [square brackets]
final String scheme = "http://"; // TODO: Currently this is just a blank link
Linkify.addLinks(linkText, pattern, scheme);
我做了類似這樣的事情:[格式化TextView看起來像鏈接](http://stackoverflow.com/q/11820526/1267661)。如果你將鏈接中的技術與我的'swapSpans()'方法結合起來,你應該可以做你想做的。 – Sam