سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top