I have 3 EditText elements and I want to switch from one field to another if there are 4 characters in the input.
I use TextWatcher for this:
getEditView(R.id.edit_code1).addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void afterTextChanged(Editable input) {
if(input.length() == 4){
getEditView(R.id.edit_code2).requestFocus();
}
}
});
The input type for EditText is "textCapCharacters"
When you make a long press on a key to get a number, for example, holding R to get 4, most devices will not add letters until the user stops holding the button and shoots after TextChanged after the letter 4 is selected. On the HTC keyboard (in In this case, HTC Desire on 2.3.5) is not. Despite the fact that the user still holds the button, R is added to EditText, and afterTextChanged is launched, and the code performs its task and puts focus on the next field.
? onKeyDown/Up , .