0

I'm currently trying to implement this:

image

I've already done the spinner part, though the phone EditText, I'm not so sure about how to make a TextWatcher for it.

I have 2 options:

  1. I use:

    phoneNumberET.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

  2. Or, I use

phoneNumberET.addTextChangedListener(new PhoneNumberFormattingTextWatcher("countryCode"));

Both of these have their flaws. In #1, it won't properly format since the country code isn't found in the EditText, but in the Spinner.

In #2 I can only use this in API level 21 and above.

So, is there a solution that can let me format the phone number properly with a country code from the spinner and be available from below API 21?

Community
  • 1
  • 1
Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117

1 Answers1

0

Earlier platform levels don't have an API for phone number formatting in other regions, you'll need to bundle it with your app. You can use a library such as googlei18n/libphonenumber (or a fork like libphonenumber-android) to provide the data and formatting, then add a TextWatcher for integration with Android.

ephemient
  • 198,619
  • 38
  • 280
  • 391