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
Just do this:
// ****** Every first letter capital in word *********
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
/>
//***** if all letters are capital ************
android:inputType="textCapCharacters"
You should put android:inputType="textCapCharacters"
with Edittext in xml file.
Use input filter
editText = (EditText) findViewById(R.id.enteredText);
editText.setFilters(new InputFilter[]{new InputFilter.AllCaps()});
edittext.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable et) {
String s=et.toString();
if(!s.equals(s.toUpperCase()))
{
s=s.toUpperCase();
edittext.setText(s);
}
editText.setSelection(editText.getText().length());
}
});
try this code it will make your input into upper case
edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
Simply, Add below code to your EditText of your xml file.
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
And if you want to allow both uppercase text and digits then use below code.
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"