如何在我的适配器项目视图中自动链接 @mentions?

How can I autolink @mentions in my adapter itemview?

我正在使用 Linkify 搜索 @symbol 之后的字符串。为什么它们不在我的 TextView 中变成链接?我是否必须在 XML 中设置其他内容,例如 android:linksClickable="true"

feedItemView.messageText.setText(message.getString("messageText"));
Pattern userMatcher = Pattern.compile("\B@[^:\s]+");
String userViewURL = ".activity.UserProfileActivity://";
Linkify.addLinks(feedItemView.messageText, userMatcher, userViewURL);

我使用了以下代码:

feedItemView.messageText.setText(yeet.getString(ParseConstants.KEY_NOTIFICATION_TEXT));

Linkify.TransformFilter filter = (match, url) -> match.group();

Pattern mentionPattern = Pattern.compile("@([A-Za-z0-9_-]+)");
String mentionScheme = "http://www.twitter.com/";
Linkify.addLinks(feedItemView.messageText, mentionPattern, mentionScheme, null, filter);

我还确保从该 TextView 的 XML 中删除 android:autoLink="all"。这将删除 web links 的自动 link 功能,因此您需要将其添加到处理显示该 TextView 的方法中:

Pattern urlPattern = Patterns.WEB_URL;
Linkify.addLinks(tweet, urlPattern, null, null, filter);