-2

What I have currently

  • I am using a editText
  • On clicking of editttext keyboard pops up
  • Now I use keyboard to type

What I am trying to achieve:

  • On click of search icon on keyboard I want to close the keyboard
  • On click of recommendation shown on keyboard words for edit text how to close the keyboard

What I am able to achieve: On click of search icon on keyboard I want to close the keyboard

getSearchView().setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    hidekeyBoard(context,v);
                    return true;
                }

                return false;
            }
        });

What I am not able to achieve: On click of recommendation shown on keyboard words for edit text how to close the keyboard

Devrath
  • 37,389
  • 47
  • 165
  • 245

1 Answers1

0
 getSearchView().setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean actionSearchDone = false;
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                //TODO do search action of your logic
                InputMethodManager inputMethodManager = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                if (inputMethodManager != null) {
                    inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
                actionSearchDone = true;
            }
            return actionSearchDone;
        }
    });
Raghul Vaikundam
  • 540
  • 3
  • 14