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");
TextView numberText = (TextView) findViewById(R.id.event_number);
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!