Thursday, 31 March 2022

maxLength causes a crash while a longer text is pasted in

I have declared in my fragment a textInputLayout which contains an edit text with parameters

     android:inputType="textCapCharacters"
     android:maxLength="3"
     android:maxLines="1"

and it works correctly on most devices, it "survives" while user is trying to input more than 3 characters, but IF user tries to paste a string, which contains more than 3 characters it ends up crashing.

"java.lang.IndexOutOfBoundsException: setSpan (0 ... 10) ends beyond length 3" enter image description here

and just to be clear, the app doesn't crash after pasting longer strings on most of the devices but on some it does, and thus is why I'm here, is there any way I could prevent that?



from maxLength causes a crash while a longer text is pasted in

No comments:

Post a Comment