Saturday, December 8, 2012

Re: [android-developers] Re: Can't Use Raw Links and Anchor Links in One TextView?

TreKing wrote:
> On Fri, Dec 7, 2012 at 12:44 PM, skink <pskink@gmail.com> 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.

me too, instead of passing 0 as the flags in setSpan it should be
rather:

int flags = html.getSpanFlags
(span);
ss.setSpan(span, start,
end, flags);

pskink

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment