Reputation: 207
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);
}
}
Any help or advise appreciated !!
Thanks.
Upvotes: 0
Views: 1306
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
Reputation: 637
You need to call Linky.addLinks(this, Linkify.ALL)
after the text has been set, not in the constructor.
Upvotes: 1