AutoLink @mentions in a twitter client

我与影子孤独终老i 提交于 2020-01-04 05:18:08

问题


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.


回答1:


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 a TransformFilter 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.



来源:https://stackoverflow.com/questions/4590384/autolink-mentions-in-a-twitter-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!