1

I am trying to view Keyboard with Next Button on Multiline Edit text. But it is not working for me.

Ashish Wadatkar
  • 427
  • 2
  • 5
  • 19
  • 1
    how is it "not working"? what does it do if you press Next? and some code please? – josephus Sep 13 '12 at 05:28
  • Possible duplicate of [Multiline EditText with Done SoftInput Action Label on 2.3](http://stackoverflow.com/questions/5014219/multiline-edittext-with-done-softinput-action-label-on-2-3) – Richard Le Mesurier Oct 15 '15 at 09:59

2 Answers2

2

You cannot set an IME Action on a multi-line edit text since the keyboard button that would be used for the next/done/search/... action is bound to be a ENTER/RETURN button to insert a line break.

Till - Appviewer.io
  • 4,529
  • 1
  • 31
  • 35
0

Fear not, it can be done. Though the following code works perfectly, but unfortunately I don't remember where I got the code from exactly and so cannot give the author the credit he/she so deserves.

////////////Code to Hide SoftKeyboard on Enter (DONE) Press///////////////
editText.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD|InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
editText.setImeActionLabel("DONE",EditorInfo.IME_ACTION_DONE);              //Set Return Carriage as "DONE"
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) 
    {
                if (event == null) {
                    if (actionId == EditorInfo.IME_ACTION_DONE) {
                        // Capture soft enters in a singleLine EditText that is the last EditText
                        // This one is useful for the new list case, when there are no existing ListItems
                        editText.clearFocus();
                        //hide SoftKeyboard
                        InputMethodManager inputMethodManager = (InputMethodManager)  getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
                        inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
                    }

                    else if (actionId == EditorInfo.IME_ACTION_NEXT) {
                        // Capture soft enters in other singleLine EditTexts
                    } else if (actionId == EditorInfo.IME_ACTION_GO) {
                    } else {
                        // Let the system handle all other null KeyEvents
                        return false;
                    }
                } 
        else if (actionId == EditorInfo.IME_NULL) {
                    // Capture most soft enters in multi-line EditTexts and all hard enters;
                    // They supply a zero actionId and a valid keyEvent rather than
                    // a non-zero actionId and a null event like the previous cases.
                    if (event.getAction() == KeyEvent.ACTION_DOWN) {
                        // We capture the event when the key is first pressed.
                    } else {
                        // We consume the event when the key is released.
                        return true;
                    }
                } 
        else {
                    // We let the system handle it when the listener is triggered by something that
                    // wasn't an enter.
                    return false;
                }
                return true;
        }
});

For passing the focus on to the Next EditText use edit_text2.requestFocus() and remove the Hide SoftKeyboard code.

Kaushik NP
  • 6,733
  • 9
  • 31
  • 60