Using below code i have created Linkify function. Here I have created MainActivity class and In main.xml layout I have added Text View property. Below code will clearly described you how to make Linkify function.
Step(1)-Create MainActivity-
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView WebSiteone = (TextView) findViewById(R.id.textview1);
WebSiteone.setText("Go to : google.com");
Linkify.addLinks(WebSiteone, Linkify.WEB_URLS);
TextView WebSitetwo = (TextView) findViewById(R.id.textview2);
WebSitetwo.setText("Go to : Findnerd.com");
Linkify.addLinks(WebSitetwo, Linkify.WEB_URLS);
TextView myCustomLink = (TextView) findViewById(R.id.textView3);
Pattern p1 = Pattern.compile("\\bAndroid+\\b");
myCustomLink.setText("Click on Android " +
"to search it on google");
Linkify.addLinks(myCustomLink, p1, "http://www.google.ie/search?q=");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
0 Comment(s)