我正在尝试插入指向 TextView 的链接,以使它们开始新的活动。我为我的Utils
班级写了一个方法来做到这一点:
public static final String tagPattern = "#([^ ]+)";
public static final String tagReplace = "<a href=\"org.openihs.seendroid://display/tag/$1/\">#$1</a>";
public static final String userPattern = "@([^ ]+)";
public static final String userReplace = "<a href=\"org.openihs.seendroid://display/user/$1/\">@$1</a>";
static public void linkify(TextView view) {
String text = view.getText().toString();
text = text.replaceAll(Utils.tagPattern, Utils.tagReplace);
text = text.replaceAll(Utils.userPattern, Utils.userReplace);
view.setMovementMethod(LinkMovementMethod.getInstance());
view.setText(Html.fromHtml(text));
Log.d("SeenDroid", text);
Linkify.addLinks(view, Linkify.ALL);
}
一个示例输出(到 logcat)是:
foo <a href="org.openihs.seendroid://display/tag/bar/">#bar</a> baz http://google.fr/
而真正的 UI 将http://google.fr/作为链接(预期行为)提供,但#bar
作为普通文本(意外行为)。
TextView 在 ListView 中。
有什么想法可以解决这个问题吗?
问候, ProgVal