Home > General > How do I make links in a TextView clickable?

How do I make links in a TextView clickable?

When I wanted to show some TextView with click able and make it as a link to open a web pages in separate browser.
Android is highlighting the links in the TextView, but they do not respond to clicks

 Lets example – I wanted to show my website –

                android:textSize=”12dip” />

 But this “URLs” is not clickable, hence I changed my code (check bold colored clickable)

                android:textSize=”12dip” />

Even though it wouldn’t work, it will clickable but it wouldn’t open any browser so –

hence I changed my code (check bold colored clickable)

                android:textSize=”12dip” />

 Now, it will open web pages, but here   android:linksClickable=”true” not required.

Some other solution and suggestion to user. –

The above solutions didn’t work for me, but the following did (and it seems a bit cleaner).
First, in the string resource, define your tag opening chevrons using the HTML entity encoding, i.e.:

Sometimes android:autoLink=”web” would work for that situation –

&lt;a href="http://www.google.com">Google&lt;/a>
Not like below 
<a href="http://www.google.com">Google</a>

In general, encode all the chevrons in the string like that. BTW, the link must start with http://
Then set this option on your TextView:


Finally, in code, do:


Note - 
This will create an HTML Parser everytime this code is executed. Be aware of that if you use this to create links 
inside a list item or at other performance critical places in your app.</br> 
During creation of a listitem this increases the execution time of my getView Methods off 50% 

This is how I solved clickable and Visible links in a TextView (by code) 
private void setAsLink(TextView view, String url){
        Pattern pattern = Pattern.compile(url); 
        Linkify.addLinks(view, pattern, "http://"); 
        view.setText(Html.fromHtml("<a href='http://"+url+"'>http://"+url+"</a>")); 
Be sure to not use setAutoLinkMask(Linkify.ALL) when 
using setMovementMethod(LinkMovementMethod.getInstance()) and 
Html.fromHTML() on properly formatted HTML links (for example, <a href="http://www.google.com/">Google</a>). 
Categories: General
  1. cnatraining
    June 27, 2012 at 5:56 am

    Howdy! I’m at work browsing your website from my new apple iphone! Just wanted to write I love reading through your blog and look forward to all your posts! Carry on the superb work.

  2. seizedcars
    July 3, 2012 at 7:11 am

    Hello!Now i’m on the job surfing around your personal blog site by my personal completely new iphone 4! Just plan to write I really like browsing your personal blog and also look in front to your complete discussions! Keep up this excellent work!

  3. autoauctions
    July 18, 2012 at 2:43 pm

    Hi there!I am just in the office exploring your personal www from my brand new iphone 3gs! Just simply choose to declare I really like examining your current blog and also look ahead to every one of your blogposts! Keep up the particular superb work.

  4. March 6, 2013 at 8:15 pm

    use onClick tag in xml and use that method implementation in activity

  1. February 26, 2013 at 9:44 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: