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?

4

1 回答 1

0

较早的平台级别在其他地区没有用于电话号码格式的 API,您需要将其与您的应用程序捆绑在一起。您可以使用诸如googlei18n/libphonenumber 之类的库(或诸如libphonenumber-android之类的分支)来提供数据和格式,然后添加一个TextWatcher以与 Android 集成。

于 2017-09-04T20:25:52.410 回答