Twitter 客户端中的自动链接@提及
我正在构建一个基本的 Twitter 客户端应用程序。我正在尝试弄清楚如何使保存推文的 TextView 自动链接 @mentions,以便它们链接到任何人的 Twitter 页面,就像在 Twitter 网站上一样。我的猜测是,这将涉及制作一个自定义 TextView 并将其添加到已经处理网站、电子邮件、地图等自动链接的部分中。这是实现此类目标的正确方法吗?或者我应该使用库存 TextView 并通过在将推文放入视图之前解析推文来处理此问题?如果我应该采用自定义视图路线,任何人都可以为我指出正确的方向,以了解如何将此功能添加到自动链接中吗?如果我应该使用库存 TextView 并在将推文放入视图之前在 java 中处理它,我如何获得它“链接”文本我唯一的猜测是使用类似 .fromHTML() 的东西,但我什至不确定如果这支持该标签。
I am building a basic twitter client application. I am trying to figure out how to make the TextView that holds the Tweets to autoLink the @mentions so that they link to the twitter page of whoever it is the same as it does on the twitter website. My guess is that this is going to involve making a custom TextView and adding this into the part that already handles the auto linking of websites,emails,maps and such. Is this right approach to achieving something like this? or should I be using a stock TextView and handling this by parsing the tweet before it gets put into the view? If I should be going the custom view route could anyone point me in the right direction for how to get this capability added to the autolink? And if I should be using the stock TextView and handling it in java before the tweet gets put into the view how do I get it "linkify" the text my only guess is using something like .fromHTML() but I'm not even sure if this supports the tag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 Linkify 类,包括接口 Linkify.MatchFilter 和
Linkify.TransformFilter。您应该能够设置一个适用于
@
链接的MatchFilter
以及一个将它们转换为适当 URL 格式的TransformFilter
。这里有一个页面,引导您完成这些类的使用;它甚至使用 Twitter 作为使用 TransformFilter 的示例。
Have a look at the Linkify class, including the interfaces Linkify.MatchFilter and
Linkify.TransformFilter. You should be able to set up a
MatchFilter
that works on@
links, and aTransformFilter
that translates them into the appropriate URL format.Here's a page that walks you through the usage of these classes; it even uses Twitter as an example for using
TransformFilter
.