Linkifying a TextView after setting text

Just a quick one.  You probably already know that you can automatically convert URLs in a TextView into clickable links like this:

mTextView.setAutoLinkMask(Linkify.WEB_URLS);

I recently learned that this will only work where you can call setAutoLinkMask() before setting text in the TextView.  The simple solution is to set the text after calling setAutoLinkMask(), but if you cannot do this, as in my case, then you can just as simply use the static addLinks() method in the Linkify class:

 Linkify.addLinks(mTextView, Linkify.WEB_URLS);

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s