Home > Android > Android Creating links using Linkfy

Android Creating links using Linkfy

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);
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);
//map address:
TextView myLocation = new TextView(this);
myLocation.setText("1 Dizengoff, Tel Aviv, IL");
Linkify.addLinks(myLocation , Linkify.MAP_ADDRESSES);
TextView myEmail= (TextView) findViewById(R.id.my_web_site);
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=");