Android Linkify
Hey everyone,
This isn’t really a full post – more just me ranting about something awesome I discovered recently.
In one of my applications (currently under development) I wanted to show users details about certain events/venues, and wanted to link addresses so that they would automatically pull up a GPS intent, and link phone numbers so that they would automatically pull up a phone call intent.I was prepared to spend some time ripping apart sample text with REGEX, and then manually linking them with the appropriate intents, but luckily the folks at Google had my back on this one and I ran into this nifty class Linkify.
This will be a short example on how to use Linkify (even though it’s pretty simple), but I thought writing a blog post on it would be useful since it seems like a pretty useful class in a lot of applications and I’m sure not many people know about it…
TextView addressText = (TextView) findViewById(R.id.event_address); addressText.setText("436 Mayfield Ave, Stanford, CA"); Linkify.addLinks(addressText, Linkify.MAP_ADDRESSES); TextView numberText = (TextView) findViewById(R.id.event_number); numberText.setText("630-857-0720"); Linkify.addLinks(numberText, Linkify.PHONE_NUMBERS);
And that’s it! Run the Activity as you normally would and you should see that both text views are highlighted with all the correct intents built into it!
Happy coding,
– jwei
Thanks for your information.!! 🙂
Thanks but I want to know more about Linkify class
Way cool, thanks Jason! Actually, loving the blog as a whole, super helpful 🙂
Excelent!!!! Thanks 😉