android - linkyfy some text in TextView -


i have string in textview , want linkify substring string. example:

click here know more.

i'm getting string dynamically. have search if has click here , convert link .how can linkify "click here".

to find pattern inside text , replace it, use this:

pattern p = pattern.compile("click here"); matcher m = p.matcher("for more info, click here"); stringbuffer sb = new stringbuffer(); boolean result = m.find(); while(result) {     m.appendreplacement(sb, "<a href=\"www.mywebsite.com\">click here</a>");     result = m.find(); } m.appendtail(sb); string strwithlink = sb.tostring();  yourtextview.settext(html.fromhtml(strwithlink)); yourtextview.setmovementmethod(linkmovementmethod.getinstance()) 

this code search inside string , replaces "click here" link.

and @ end, not add android:autolink="web" xml resource (section textview), otherwise a-tags not rendered correctly , not clickable longer.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -