Linkify adds Text to the End of Links
I would like to add a link to a textview and have the following code:
TextView textview = (TextView) findViewById开发者_运维知识库(R.id.mytext);
Pattern myPattern = Pattern.compile("WordToBeLinked");
String link = "http://mydomain.com/something";
Linkify.addLinks(textview, myPattern, link);
So everything works as it should: the word "WordToBeLinked" is linked and it opens the browser with the link BUT somehow Linkify adds the "WordToBeLinked" to the URL so the URL that is called looks like this:
http://mydomain.com/somethingWordToBeLinked
Can somebody please tell me what i did wrong? Thanks
You have to use TransformFilter. Hope this help.
TextView textview = (TextView) findViewById(R.id.mytext);
textview .setText("WordToBeLinked");
TransformFilter mentionFilter = new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
return new String("http://mydomain.com/something");
}
};
Pattern pattern = Pattern.compile(".");
String scheme = "";
Linkify.addLinks(textview, pattern, scheme, null, mentionFilter);
Since there is no Pattern and scheme in your case, so they are just place holder.
That is the exact behavior described in the docs of linkify.
If you want to replace your word by a link then do :
you could use the overloaded method and use a transform filter to rewrite the final url.
精彩评论