문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top