Question

The following code don't work-

   TextView myLocation = new TextView(this);
   myLocation.setText("Sodala, Jaipur, Rajasthan, IN");
   Linkify.addLinks(myLocation , Linkify.MAP_ADDRESSES);
   mainLayout.addView(myLocation);
Was it helpful?

Solution

It seems your address is too vague for Linkify. I am unaware of what addresses look like in India (if they are different at all), so consider New York in the US:

myLocation.setText("New York, NY   34 Maint St New York, NY");

"New York, NY" alone is not a valid map address for Linkify.

You can try to set your own pattern, by following an example here to match anything with ", IN".

OTHER TIPS

Here is a simplified version of addLinks with a custom pattern.:

Pattern pattern = Pattern.compile(".*", Pattern.DOTALL);
addressTextView.setText(address);
Linkify.addLinks(addressTextView, pattern, "geo:0,0?q=");

I use this for german and US addresses, since google-maps is pretty smart when searching an address other localities should work find too.

This highlight's all the content's of the TextView which fits my use-case. If the address is somewhere inside of the string a smarter pattern needs to be applied here.

you try

http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/

// Recognize all of the default link text patterns 
    Linkify.addLinks(text, Linkify.ALL);

or http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/

TextView myCustomLink2 = new TextView(this);
Pattern pattern2 = Pattern.compile("[a-zA-Z]+");
myCustomLink2.setText("press one of these words to search it on google: Android Linkify dzone");
Linkify.addLinks(myCustomLink2,pattern2, "http://www.google.ie/search?q=", myMatchFilter, null);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top