3

I want to create the linkify with a simple html string like "Search stackoverflow with Google`". Have tried to use regular expression for detecting text parts with the following code, but the word "stackoverflow" did not show as a link on the textview

String content = "Search <b>stackoverflow<b> with Google";    
TextView tv = (TextView)this.findViewById(R.id.tv);
tv.setText(Html.fromHtml(content));
Pattern pattern = Pattern.compile("<b\b[^>]*>(.*?)</b>");
Linkify.addLinks(tvContent, pattern, "http://www.google.com/search?q=",
            null, myTransformFilter);

Any help on this would be appreciated. Thanks alot....

AdrDev_CTS
  • 245
  • 4
  • 11

1 Answers1

0

you might be able to use Html.fromHtml() to get the effect you are looking for.

something like this would do it I think:

tv.setText(Html.fromHtml("<a href=\"http://www.google.com/search?q=\">Search content with Google</a>");

note: I didn't compile this, not sure if I got the escaping correct, but you should be able to get the idea.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156