0

I would like to open the keyboard for another EditView (than the one I am using) when I click Enter on it (when I am in the first EditView).

The scenario should be like this : I am writing something in the keyboard for the 1st EditView, I have finished so I press "Enter" and it opens the keyboard for the second EditView.

I tried different codes but no success, if somebody could help me please.

user3460225
  • 69
  • 1
  • 1
  • 7

3 Answers3

0

if i understood here is the answer

editText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
Igor Ronner
  • 1,565
  • 2
  • 14
  • 31
  • What would be the complete code? I tried this which doesnt work: mEditText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { mEditText2.setImeOptions(EditorInfo.IME_ACTION_NEXT); return true; } return false; } }); – user3460225 Aug 13 '14 at 17:29
  • you don't need this. Use just mEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT); and test – Igor Ronner Aug 13 '14 at 17:32
0

You basically want to switch the focus from 1 EditText to another after pressing Enter.

This can very easily be done by setting the 'setNextFocusDownId' option on your 1st EditText.

firstEditText.setNextFocusDownId(R.id.secondEditTextId);

Moonbloom
  • 7,738
  • 3
  • 26
  • 38
  • Your answer seems interesting but I cannot make it work on my code... Could you give me a sample of code that is working please? – user3460225 Aug 13 '14 at 17:40
  • Sure. `EditText firstEditText = (EditText) findViewById(R.id.first);` `EditText secondEditText = (EditText) findViewById(R.id.second);` `firstEditText.setNextFocusDownId(R.id.second);` – Moonbloom Aug 13 '14 at 21:26
0

I have found by searching with 'setNextFocusDownld' like Kasper suggested, using this answer : Android Softkey's next button not taking focus to spinner

The code I used is:

mEditText.setNextFocusDownId(R.id.textView2b);
        mEditText.setOnKeyListener(new OnKeyListener() {

            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN)
                        && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on Enter key press
                    mEditText.clearFocus();
                    mEditText2.requestFocus();
                    return true;
                }
                return false;
            }
        });
        mEditText2.setOnKeyListener(new OnKeyListener() {

            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN)
                        && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on Enter key press
                    mEditText2.clearFocus();
                    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mEditText2.getWindowToken(), 0);
                    return true;
                }
                return false;
            }
        });
Community
  • 1
  • 1
user3460225
  • 69
  • 1
  • 1
  • 7