2

I've got an EditText and I would like to set the text to uppercase. I used setFilters(new InputFilter[]{new InputFilter.AllCaps()}) which is working most of the time but not on Samsung with autocorrect and autocompletion.

On that kind of device each time I type a letter it replace the former one, leaving me with a 1 character text long. The only way to be able to type multiple characters is to lock caps on keyboard.

I would like to have a solution working on every device, does anyone know how to achieve that ?

Tibo
  • 523
  • 1
  • 8
  • 20
  • Possible duplicate of [In Android EditText, how to force writing uppercase?](http://stackoverflow.com/questions/15961813/in-android-edittext-how-to-force-writing-uppercase) – LeDaheronF May 22 '17 at 09:29
  • 2
    I would like to know if there is a solution to solve this issue using InputFilter (which is for me the most elegant solution to force writing uppercase) – Tibo May 22 '17 at 10:16

1 Answers1

0

This is Samsung's keyboard bug and you can't do anything with it. (except android.os.Build.MANUFACTURER check)

Look at InputFilter#filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) method

this method is called when the buffer is going to replace the range dstart … dend of dest with the new text from the range start … end of source.

And the output for:

Normal device:

"s" 0 1 "" 0 0 -> "S"
"e" 0 1 "S" 1 1 -> "E"

Samsung:

"s" 0 1 "" 0 0 -> "S"
"e" 0 1 "S" 0 1 -> "E"

The Samsung's result doesn't differ from a such result in case you are going to replace one character with other one, for example with using Insert option of clipboard.

Beloo
  • 9,723
  • 7
  • 40
  • 71