PhoneNumberFormattingTextWatcher not working

I am trying to use PhoneNumberFormattingTextWatcher but nothing happens as if the code is not there

here is the code

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    EditText PhoneEdit = (EditText) findViewById(R.id.editText1); 
    PhoneEdit.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
}

      

when you enter 002010555666 it still remains the same - or + or (), the same without formatting is there anything in the code

help

+6


source to share


5 answers


You had the same problem but after uninstalling android:digits="1234567890+"

it disappeared.



+8


source


I added a comment to YTerle, but I would like to put the complete answer below:

<android.support.design.widget.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="phone"
                android:hint="@string/phone_number"
                android:layout_marginBottom="5dp"
                android:ems="10"
                android:maxLength="14"
                android:id="@+id/phone" />

      



Then in the code, enter the following:

phoneView.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

      

+3


source


I was having problems even after adding android:inputType="phone"

to XML.

The solution was to set the language in the phone :

Settings -> Language Search -> select English (US)

The format (999) 999-9999 is mainly used in the USA, so the phone language should only be set to it.

+2


source


I used this in my app and it worked fine in the emulator (Android_4.2_Emulator_Smartphone_Nexus_S, using platform 4.4.2, API 19), but had no effect when run on my Samsung Tab 3 device with platform 4.1.2, API 17. Maybe it is device dependent? The documentation indicates that it was introduced in API 1, so I would have thought it should have all the kinks developed by now, but obviously not.

0


source


Final Solution: The problem is only related to the android: inputType you selected in the XML. This won't work with "number". You need to select "phone" or not inputType.

0


source







All Articles