In my Android application I have different EditText
where the user can enter information. But I need to force user to write in uppercase letters.
Do you know a function to do that?
Android actually has a built-in InputFilter just for this!
edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
Be careful, setFilters
will reset all other attributes which were set via XML (i.e. maxLines
, inputType
,imeOptinos
...). To prevent this, add you Filter(s) to the already existing ones.
InputFilter[] editFilters = <EditText>.getFilters();
InputFilter[] newFilters = new InputFilter[editFilters.length + 1];
System.arraycopy(editFilters, 0, newFilters, 0, editFilters.length);
newFilters[editFilters.length] = <YOUR_FILTER>;
<EditText>.setFilters(newFilters);