On Fri, Dec 7, 2012 at 12:44 PM, skink <[email protected]> wrote:
> try this:
>
> String str = "http://www.google.com <a href=\"
> http://www.google.com\">Google</a>";
> Spanned html = Html.fromHtml(str);
> Object[] spans = html.getSpans(0, html.length(), URLSpan.class);
> tv.setAutoLinkMask(Linkify.ALL);
> tv.setText(html);
>
> SpannableString ss = (SpannableString) tv.getText();
> for (int i = 0; i < spans.length; i++) {
> URLSpan span = (URLSpan) spans[i];
> int end = html.getSpanEnd(span);
> int start = html.getSpanStart(span);
> ss.setSpan(span, start, end, 0);
> }
>
Just want to add to this for posterity's sake. After fiddling with real
data, I had to initialize the TextView as such:
tv.setAutoLinkMask(Linkify.ALL);
* tv.setMovementMethod(LinkMovementMethod.getInstance());*
Apparently, if you only have an anchored link in the TextView, it does not
get the link functionality implicitly from the link mask. You have to call
setMovementMethod explicitly to ensure this works.
-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en