Linkfy is a class that lets you create links from TextViews.
You can create links not just to web sites, but to also map addresses, emails and even phone numbers.
Linking to a web address
TextView myWebSite = (TextView) findViewById(R.id.my_web_site);
myWebSite.setText( "http://http://www.google.com/" );
Linkify.addLinks(myWebSite , Linkify.WEB_URLS);
|
Linking to a phone number
TextView myPhone = (TextView) findViewById(R.id.my_web_site);
myPhone .setText( "9999590698" );
Linkify.addLinks(myPhone , Linkify.PHONE_NUMBERS);
TextView myLocation = new TextView( this );
myLocation.setText( "1 Dizengoff, Tel Aviv, IL" );
Linkify.addLinks(myLocation , Linkify.MAP_ADDRESSES);
mainLayout.addView(myLocation);
TextView myEmail= (TextView) findViewById(R.id.my_web_site);
myEmail.setText( "kumar.narender1991@gmail.com" );
Linkify.addLinks(myEmail , Linkify.PHONE_NUMBERS);
|

Using a regular expression for filtering strings
TextView myCustomLink = new TextView( this );
Pattern pattern = Pattern.compile( "[a-zA-Z]+&" );
myCustomLink.setText( "press Linkify& or on Android& to search it on google" );
Linkify.addLinks(myCustomLink,pattern, "http://www.google.ie/search?q=" );
mainLayout.addView(myCustomLink);
|