Skip to content

Instantly share code, notes, and snippets.

@paddyzab
Created May 2, 2013 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paddyzab/5501892 to your computer and use it in GitHub Desktop.
Save paddyzab/5501892 to your computer and use it in GitHub Desktop.
Create clickable Link from Url on a TextView.
public static void addLinks(TextView view, String url) {
if (null != view && null != url) {
view.setLinksClickable(true);
view.setMovementMethod(LinkMovementMethod.getInstance());
String template = "<a href='{0}'>{1}</a>";
String finalText = format(template, url, TextUtils.htmlEncode(view.getText().toString()));
view.setText(Html.fromHtml(finalText));
} else {
if (kcDebug.isDebuggingOn) {
Log.e(TAG, "addLinks - Invalid arguments" + kcDebug.kFixYourCode);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment