Phone number formatting an EditText in Android

前端 未结 14 916
情深已故
情深已故 2020-12-02 12:03

I am making a simple Address Book app (targeting 4.2) that takes name, address, city, state, zip and phone.

I want to format the phone number input as a phone number

14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 12:32

    Simply use the PhoneNumberFormattingTextWatcher, just call:

    editText.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
    

    Addition
    To be clear, PhoneNumberFormattingTextWatcher's backbone is the PhoneNumberUtils class. The difference is the TextWatcher maintains the EditText while you must call PhoneNumberUtils.formatNumber() every time you change its contents.

提交回复
热议问题