0

I have been trying to have my editText accept phone values only as well as extensions. I managed to do this in its xml phone using.

android:inputType="phone"
android:digits="0123456789()- x"

Now the other problem I have been attempting to figure out is how to have editText display ( ) - at all times and when more numbers pressed (ooo) ooo-oooo xoooo. Currently I have editText

editTextpponentTeamContactPhone.addTextChangedListener(new PhoneNumberFormattingTextWatcher() {
PhoneNumberUtils phoneNumberUtils;

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
            phoneNumberUtils.formatNumber(editTextpponentTeamContactPhone.getText().toString());
            super.onTextChanged(s, start, before, count);
        }
    });

This is close to what I want. It becomes (xxx) xxx-xxxx but not extensions so was wondering if anyone had come through something similar I am looking but not getting much luck.

Ashley Alvarado
  • 1,078
  • 10
  • 17

1 Answers1

0

To limit char lenght at TextView you can use

android:maxLength="14"

or programmatically :

textView.setFilters(new InputFilter[] { new InputFilter.LengthFilter(250) });
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
  • Well that is something that I am doing already, but the issue isn't with length. It's about showing at all times ( ) - or ( ) - x. I can modify the string but am trying to force this format in editext. – Ashley Alvarado Apr 23 '15 at 21:55
  • 1
    @AshleyAlvarado well, you can write a custom TextWatcher that will be listen your edit text changes after input text. When text.isEmpty - clean up all text view content. – Sergey Shustikov Apr 23 '15 at 21:57