void
void

Reputation: 207

Linkify Android for phone numbers, address and Email

I have a custom TextView (extends TextView) which can contain any text configured by the customer. I need to add the functionality, where user can click the phone number, address and email and app can launch appropriate app (dialer, maps, email). Please look my current implementation :

public class MyTextView extends TextView{        

    // constructors and styling of this view

   public void setStyle(){
        setLinksClickable(true);
        setMovementMethod(LinkMovementMethod.getInstance());
        Linkify.addLinks(this, Linkify.ALL);
       //setAutoLinkMask(Linkify.ALL);
   }

}
  1. What is wrong in my implementation ? I cannot click the text containing the phone number, address and email.
  2. What format for phone number, address and email should be inputted in the textview for this feature to work ?

Any help or advise appreciated !!

Thanks.

Upvotes: 0

Views: 1306

Answers (2)

void
void

Reputation: 207

I got it working. I added android:autoLink="all" to the TextView element in xml. My phone number format in the TextView was incorrect. These are some of phone number formats supported by Linkify: 12345678912, +12345678912, 1-234-567-8912, +1-234-567-8912, (1234) 567-8912, +(1234) 567-8912.

Note : There could be more supported formats too !!

Thanks

Upvotes: 2

simplatek
simplatek

Reputation: 637

You need to call Linky.addLinks(this, Linkify.ALL) after the text has been set, not in the constructor.

Upvotes: 1

Related Questions