On Friday, December 7, 2012 5:13:46 AM UTC+1, TreKing wrote:
>
> I'm trying to display some text that I get from various web sources in 
> some TextViews. The data is out of my control and may contain links to 
> other sites. The links may be "raw" or "anchored". By this I mean:
>
> Raw link is like *http://www.google.com*
> Anchored link is like *<a href="http://www.google.com";>Google</a>*
>
> I set the text on the TextView using Html.fromHtml().
>
> I'd like to be able to click any of these links to go to the linked sites, 
> but apparently the TextView can only support one or the other but not both 
> of these at the same time .. ?
>
> I can use the autoLink=true property on the TextView to make raw links 
> clickable, but the anchor links are not affected.
>
> I can use the LinkMovementMethod to get the anchor link to be clickable, 
> but the raw links are not affected.
>
> But if I use both the autoLink and LinkMovementMethod, the autoLink 
> property seems to take precedence and makes the raw links clickable but the 
> anchor links do nothing.
>
> I'm finding discussion on StackOverflow and this group about enabling 
> linking in a TextView using each method, but nothing about this apparent 
> conflict when using both. Nor do I see a bug report about this issue. I 
> must be missing obvious ... surely I can have these two types of links work 
> in one TextView.
>
> My alternative would be to use a WebView, but that would complicate my 
> layout, and it really seems like this should work ...
>
> Can anyone confirm is this is a bug or feature or what I'm missing and 
> offer a solution or workaround?
>
> Thanks!
>
>
> -------------------------------------------------------------------------------------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago 
> transit tracking app for Android-powered devices
>

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);
        }

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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to