Linking adds text to the end of links

I would like to add a link to the text view 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 connected and opens the browser with a link. BUT somehow Linkify adds "WordToBeLinked" to the URL, so the called URL looks like this:

http://mydomain.com/somethingWordToBeLinked

Can someone please tell me what I did wrong? Thanks

+3
source share
2 answers

You must use TransformFilter. I hope for 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 in your case there is no template and diagram, therefore they are only the owner of the place.

+4
source

The exact behavior described in the binding documents .

, :

URL-.

0

All Articles