I have an edittext and I want any character that I type in edittext show in Capital letter. I have used this:
edittext.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
But it is not working. I want to do it dynamically. Any ideas.
I have an edittext and I want any character that I type in edittext show in Capital letter. I have used this:
edittext.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
But it is not working. I want to do it dynamically. Any ideas.
You just need to try with android:inputType attribute.
As per your requirement, you can include android:inputType="textCapCharacters"
Type of hack,Try this:
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 arg0) {
String s=arg0.toString();
if(!s.equals(s.toUpperCase()))
{
s=s.toUpperCase();
edittext.setText(s);
edittext.setSelection(s.length());
}
}
});
This should work(don't have time to check)try putting the lines in onTextChanged in afterTextChanged if this doesn't work..
For doing it dynamically:
edittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
EditText txt = FindViewById<EditText>(Resource.Id.textView1);
txt.SetFilters(new Android.Text.IInputFilter[] {
new Android.Text.InputFilterAllCaps()
});
<EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:capitalize="characters"/>
you can try this too, if nothing else works
String text=editText.getText().toString();
editText.setText(text.toUpperCase());
add this code to the onTextChangeListener of EditText