I have 3 EditText (editText1, editText2 and editText3) in my Fragment. When I click "Next" on my soft keyboard the focus currently goes to the next EditText. I also check if the content of those Editboxes are valid (like is valid email etc.). Lets assume the checkEditText_() are working properly.
For editText1 I solved that like:
editText1.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_NAVIGATE_NEXT)) {
if (!checkEditText1()) { // editText1 content fail
editText1.clearFocus();
editText1.requestFocus();
edi tText1.selectAll();
} else if (!checkEditText2()) { // editText2 content fail
editText1.clearFocus();
editText2.requestFocus();
} else if (!checkEditText3()){ // editText3 content fail
editText1.clearFocus();
editText3.requestFocus();
}
return true;
}
return false;
}
});
For editText1, when its own content is not suceed, it shall remain and keep the focus on itself. Otherwise it shall focus on the other two remaining editText's to push the user to correct the error there..
But when checkEditText1() fails, it is not focusing like in the first if-clause...
How can I remain in the current EditText properly?