Question

In my app I'm trying to format the phone number typed in an EditText. For that I'm using a PhoneNumberFormattingTextWatcher.

I'm having issues with this class. Trying to use the constructor PhoneNumberFormattingTextWatcher(String countryCode) doesn't compile. I can't find it in the documentation but it's definitely in the sdk (see the code source).

What's wrong with that class?

Était-ce utile?

La solution

The PhoneNumberFormattingTextWatcher(String countryCode) is hidden API, as you can see from the @hide tag in the javadoc. In other words: that particular constructor is not part of the SDK.

Autres conseils

I highly suggest you to use PhoneNumberUtils to format a phone number. https://developer.android.com/reference/android/telephony/PhoneNumberUtils.html

And especially these two methods:

  • formatNumber(String source) Breaks the given number down and formats it according to the rules for the country the number is from.
  • formatNumber(Editable text, int defaultFormattingType) Formats a phone number in-place.

According to the documentation, this CTOR is available from API21 , so you can either copy the code for pre-Lollipop, or use it when you can:

http://developer.android.com/reference/android/telephony/PhoneNumberFormattingTextWatcher.html#PhoneNumberFormattingTextWatcher(java.lang.String)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top