I have 2 EditText's on my Activity and set the maxLength
to 5.
Now I want to set the focus to editText2
, if the length of 5 is reached in editView1
...
I tried it with:
editView1.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(editView1.getText().length() == 5)
editView2.requestFocus();
return false;
}
});
But it won't work..
This solution works (no need to add android:focusable="true"\android:focusableInTouchMode="true"): final EditText userEditText = (EditText)findViewById(R. id.
Remove focus but remain focusable: editText. setFocusableInTouchMode(false); editText. setFocusable(false); editText.
You can use View. OnFocusChangeListener to detect if any view (edittext) gained or lost focus.
setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (edtPasscode3. getText(). length() == 1) edtPasscode4. requestFocus(); return false; } });
This works
final EditText editText1 = (EditText) findViewById(R.id.editText1);
final EditText editText2 = (EditText) findViewById(R.id.editText2);
editText1.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(editText1.getText().length() == 5)
editText2.requestFocus();
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With