0

I have two TextViews which could contain phone numbers. How can i automatically highlight phone numbers in a TextView and make them clickable? I tried Linkify and autolinkmask but it would falsly highlight numbers with/with more than 3 digits. For example Zip Codes.

thanks

Mahsum B
  • 23
  • 5
  • What do you mean "highlight"? As in: they contain some amount of text and some portions of that may or may not be phone numbers? Google produces [libphonenumber](https://github.com/google/libphonenumber) that does various things related to textual formats of phone numbers, maybe that's a good start. Also: depending on which formats you accept three-digit numbers can very well be phone numbers (just think of 911). – Joachim Sauer Aug 18 '21 at 08:44
  • well it should be clickable and open the phone app on the phone with the number pasted – Mahsum B Aug 18 '21 at 08:45
  • and the textview will contain long texts which could have a phone number, f.e.: "bla blablablabla and call us at: +43787856881" – Mahsum B Aug 18 '21 at 08:47

1 Answers1

0

In TextView you can set the attribute android:autoLink, i.e. android:autoLink="all".

anemomylos
  • 546
  • 1
  • 6
  • 14
  • As mentioned, i already tried that but it would highlight numbers >= 3 digits as Phone Numbers. For example "123" would be highlighted as a phone number and be clickable. Do you know if i can set a min. length? – Mahsum B Aug 18 '21 at 09:01
  • Possible duplicate of https://stackoverflow.com/questions/48879565/setting-minimum-length-for-auto-link. – anemomylos Aug 18 '21 at 09:22
  • yeah kinda, but the answer doesnt work either :/ – Mahsum B Aug 18 '21 at 10:55