Frage

I use maxlengnth for edittext, I set it 7 altough it allows to input 6 characters. It only allow 6 caharcters, instead of 7...

    <EditText
        android:id="@+id/editText1"
        style="@style/txtstyle"
        android:layout_weight="5"
        android:inputType="number"
        android:maxLength="7" >

        <requestFocus />
    </EditText>

java code

txt_phonenumber = (EditText) findViewById(R.id.editText1);
txt_phonenumber.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

What is the best and simplest working way for character limit?

War es hilfreich?

Lösung

After quick search and little testing I found the following

just remove

txt_phonenumber.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

this line. Why because The formatting is based on the current system locale and future locale changes may not take effect on this instance. For more detail see here. After removing this line you can enter 7 digits.

I hope this wil help you.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top