Closed TC-jZhang closed 4 years ago
You're overriding all links with only phone number links by using BetterLinkMovementMethod.linkify(PHONE_NUMBERS)
. I think you just need,
LinkifyCompat.addLinks(textView, Linkify.ALL)
textView.movementMethod = BetterLinkMovementMethod.newInstance().setOnLinkClickListener(onLinkClickListener)
Every time I see this I am reminded that adding linkify*
functions to BetterLinkMovementMethod
was a mistake 😄.
right, but how would I go about ONLY handling phone numbers in this case? Do I have to specifically look for a number regex?
Yep, you'll have to run a regex check. I believe you can find the regex inside Linkify.
Sounds good. Thank you for your help!!
no problem!
Patterns Class has a solution...
if (Patterns.WEB_URL.matcher(url).matches()) {
//An web url is detected
return true;
}
else if(Patterns.PHONE.matcher(url).matches()){
//A phone number is detected
return true;
}
else if(Patterns.EMAIL_ADDRESS.matcher(url).matches()){
//An email address is detected
return true;
}
I want to create functionality where I can linkify all of a textView, but only handle cases where it is a phone number on my own. For URL's, emails, etc. I want it to default to Linkify's default behavior:
right now we are doing this:
but you can see that it will only link phone numbers at this point. This is not an issue with the library, but asking more for suggestions or if there's any available API to use? Thanks!!