1

I have 2 fragments in the stack, both of them contain EditTexts. (The red EditTexts is from the bottom fragment)

When I click the soft keyboard 'next' button, the cursor should move to the 2nd edit text, but instead, it's jump to the bottom fragment EditText.

If I use 'fragmentManager.replace(new TopFragment())',so there is only 1 fragment in the stack, there is no problem, and cursor move to the 2nd EditText.

'fragmentManager.replace(...)' is not a solution, I have a callback for the bottom fragment.

enter image description here

hareesh J
  • 520
  • 1
  • 6
  • 21
itzhar
  • 12,743
  • 6
  • 56
  • 63

1 Answers1

2

What you could do is to catch the enter press in the first EditText and requestFocus() by either using an interface to talk between the fragments or export the second's fragment's EditText variable (which I won't recommend)

example:

yourEditTextFragment1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL
                && event.getAction() == KeyEvent.ACTION_DOWN) {
                // User pressed enter tell fragment 2 to requestFocus()
                // on it's EditText :)
            }
            return true;
        }
    });
Ariel Yust
  • 585
  • 4
  • 11