Android – EditText gives IndexOutOfBounds Exception while using textAllCaps

I had the same problem with textAllCaps for EditText in my application.

I have found that textAllCaps is a property for TextView only. You can not use this property for EditText.

So, I did R&D for it and found a better solution for this issue.

Rather than using textAllCaps we can use android:inputType="textCapCharacters".

E.g.

    <EditText
        android:id="@+id/edittext1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textCapCharacters"
        android:hint="@string/first_name"
        android:padding="10dp" >
    </EditText>

If we use android:inputType="textCapCharacters" it will convert all characters into UPPER CASE, like we want in textAllCaps.

P.S. If you use the shift key and type text it may convert the text in lowercase. You can always use toUpper() method in string object to convert it back to uppercase.
It may help…

You can read these details from this blog post: https://androidacademic.blogspot.com/2018/05/indexoutofbounds-exception-while-using.html

Leave a Comment