Create Android Project..
and add this code in mainactivity as given below u will understand how to linkify in android.
package com.prashant.AndroidLinkify;
import android.app.Activity;
import android.os.Bundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.text.util.Linkify;
import android.text.util.Linkify.MatchFilter;
import android.text.util.Linkify.TransformFilter;
import android.widget.TextView;
public class AndroidLinkifyMain extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView)findViewById(R.id.textView1);
textView.setText("This is a demo of custom text linkify, developed by prashant click here");
MatchFilter matchFilter = new MatchFilter() {
public final boolean acceptMatch(CharSequence s, int start, int end) {
// you can compare match over here
// return s.toString().equals("@prashant");
return true;
}
};
//to which convert
TransformFilter transformFilter = new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
return "http://prashant18993.blogspot.in/";
}
};
Pattern pattern = Pattern.compile("click here");
String scheme = "http://";
Linkify.addLinks(textView, pattern, scheme, matchFilter, transformFilter);
}
}
output:
main screen:
after click on linkify.......
and add this code in mainactivity as given below u will understand how to linkify in android.
package com.prashant.AndroidLinkify;
import android.app.Activity;
import android.os.Bundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.text.util.Linkify;
import android.text.util.Linkify.MatchFilter;
import android.text.util.Linkify.TransformFilter;
import android.widget.TextView;
public class AndroidLinkifyMain extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView)findViewById(R.id.textView1);
textView.setText("This is a demo of custom text linkify, developed by prashant click here");
MatchFilter matchFilter = new MatchFilter() {
public final boolean acceptMatch(CharSequence s, int start, int end) {
// you can compare match over here
// return s.toString().equals("@prashant");
return true;
}
};
//to which convert
TransformFilter transformFilter = new TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
return "http://prashant18993.blogspot.in/";
}
};
Pattern pattern = Pattern.compile("click here");
String scheme = "http://";
Linkify.addLinks(textView, pattern, scheme, matchFilter, transformFilter);
}
}
output:
main screen:
after click on linkify.......


No comments:
Post a Comment