0

In my application i have an edittext in which a user can Alphanumeric string. Now the point is i want that whatever the aplhanumeric or alphabetic string he types that should be converted into the capital case. For ex: if the edittext input is like:

sdhq8273dyp3

In editext when user types it should be converted to captial case

SHHQ8273DYP3

Is there any way. if in XML i am setting the Attribute android:textAllCaps="true" it is giving me the error. So how can we make the Editext aplhanumeric character to uppercase.

anand
  • 1,711
  • 2
  • 24
  • 59

6 Answers6

4

Try

 android:capitalize="characters"
 android:inputType="textCapCharacters"

This working fine in my case.

M D
  • 47,665
  • 9
  • 93
  • 114
  • 1
    As ** android:capitalize="characters"** is deprecated. This two lines works for me : **android:inputType="textCapCharacters" android:textAllCaps="true"** – Rozina May 23 '18 at 11:14
2

Take a look at http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputMethod

You'll probably want

android:inputMethod="textCapCharacters"
Tim Mutton
  • 756
  • 8
  • 17
2

Try this -

android:inputType="textCapCharacters"

You can even do this in your java code

edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
Narendra Singh
  • 3,990
  • 5
  • 37
  • 78
2
android:inputType="textCapCharacters"
edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});

These two might be useful

xenteros
  • 15,586
  • 12
  • 56
  • 91
2

You can wite this in java file.

   edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});

or you can use this is xml

   android:inputType="textCapCharacters"
Ankii Rawat
  • 2,070
  • 17
  • 17
1

You can also set it programmatically and it is for api level 14 and above only. below it you have to manually implement it.

editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT
                   + android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);

I found your problem. android:textAllCapsis for textview and not edittext. see here

Sam
  • 1,237
  • 1
  • 16
  • 29