Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneNumberFormattingTextWatcher is not working

I am trying to use PhoneNumberFormattingTextWatcher but there is nothing happening 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 entering 002010555666 it still the same no - or + or (), just the same without any formatting is there anything missing in the code

help

like image 306
Firas Shrourou Avatar asked Feb 11 '13 22:02

Firas Shrourou


3 Answers

Have had the same issue, but after removing android:digits="1234567890+" it gone.

like image 144
YTerle Avatar answered Oct 21 '22 22:10

YTerle


I added a comment to YTerle's answer, but I wanted 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 put the following:

phoneView.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
like image 5
Justin Avatar answered Oct 21 '22 22:10

Justin


I was having issues even after adding android:inputType="phone" in the XML.

The solution was to set the Language in the phone:

Settings -> Search for Language -> pick English (United States)

The format (999) 999-9999 is mostly used in the US, therefore the phone language should be set to that only.

like image 3
Akeshwar Jha Avatar answered Oct 21 '22 20:10

Akeshwar Jha