1

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?

Tranquillo
  • 235
  • 2
  • 13
  • I think you should not make things complicated here . If you only need to proceed once your first `EditText` value pass the test . Then make other non focusable untill then . Validate Edit text value with a `TextWatcher`. – ADM Dec 04 '18 at 14:35

1 Answers1

0

Use this:

     android:imeOptions="actionDone"

No need to listen any keyEvent.

kartik malik
  • 312
  • 1
  • 9
  • when I click in `editText1` done, and `checkEditText1()` returns false, I want to keep focus on `editText1` – Tranquillo Dec 04 '18 at 14:43