Friday, April 15, 2011

Custom text linkify in android

Here is the demo for custom text linkify in android.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.os.Bundle;
import android.text.util.Linkify;
import android.text.util.Linkify.MatchFilter;
import android.text.util.Linkify.TransformFilter;
import android.widget.TextView;

public class LinkifyTextDemo extends Activity {
public void onCreate(Bundle savedInstanceState) {

TextView textView = (TextView)findViewById(;
textView.setText("This is a demo of custom text linkify, developed by @Bharat");

MatchFilter matchFilter = new MatchFilter() {
public final boolean acceptMatch(CharSequence s, int start, int end) {
// you can compare match over here
// return s.toString().equals("@Bharat");
return true;
TransformFilter transformFilter = new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
return "";

Pattern pattern = Pattern.compile("@Bharat");
String scheme = "http://";
Linkify.addLinks(textView, pattern, scheme, matchFilter, transformFilter);



  1. Hi ,

    My requirement is to stop loaing link and invoke an activity.
    Any ideas on that?

  2. Your blog creativity is really good.This is one of the good quality post.Nice to read about your information.Keep it up.
    Android app developers

  3. This one article alone shows off your excellent writing skills. I am very impressed with your views and interesting content. I hope you intend to continue writing more informational articles.

    Android developers