• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TextView autoLink

 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

When using TextView autoLink xml attribute, is it possible to use html elements?

I tried it, of course, but it did not work for me.
The Text gets rendered as a link, but it is not clickable.
Having just a link, say
http://google.com or google.com without using tags works fine.

What I want to do, for example, is to show the text "Google" as a clickable link to
http://google.com only using the xml definitions.

Cheers.
 
Author
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The documentation says that only a few HTML tags are supported:
http://developer.android.com/guide/topics/resources/available-resources.html#stringresources

The trick is that your text string MUST come from a resource and not from a static string in your code.

If you look at the source code you'll see that more should be possible than just the ones that are documented:

http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/text/Html.java;h=90f5e4c683a1769c57757e21a51e2e794ed6fdf7;hb=HEAD

I see support for in the source so try it and see if it works.
 
Sonny Gill
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Ed.

The string is coming from a resource.
From the documentation, I picked up one thing that I wasn't doing - escaping quotes.
I fixed that, but that didn't have any effect.

The source code you linked to shows handling of tags.
And true enough, the tag gets rendered as a link, it is a different color and underlined.
But, you can't click it to launch the browser.

Cheers.
 
Ed Burnette
Author
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, it wouldn't work for me either. I guess that's why it's not documented.

It looks like for now you'll have to either live with the plain linkifying, or use a WebView. WebViews are nice because you can do images, text flow, tables, and all that. You can even have mixed Java/Android + JavaScript/HTML applications where the two halves are displayed on the screen seamlessly and communicate with each other. See "Section 7.3, From JavaScript to Java and Back", and try the LocalBrowser example code from the web site.
 
Sonny Gill
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ed Burnette wrote:
See "Section 7.3, From JavaScript to Java and Back"



I am right at that chaper ha ha, I actually had the book open at that page as I started to read this post!

I fudged around with the code a little.
As the following code demonstrates, the links are created, but they are just not made clickable for some reason.

Hello.java


strings.xml


main.xml


Anyway, this was just a curiosity. May be, I will check it again when a newer version of Android comes out.
 
reply
    Bookmark Topic Watch Topic
  • New Topic