3

I am showing a list with messages and each message's row has a comment button.When i click on comment button opens a comment box with edit text and button for submitting the comment.When comment box appears on screen keypad also appears for entering text.If i pressed home button before entering text then application goes background but keypad remains on screen.This is the thing irritating me.For custom list i am using a custom adapter and code for comment box is written in that adapter.I tried using

inputmgr.hideSoftInputFromWindow(txtComments.getWindowToken(), 0);

but it is not working. So how i can hide this keypad programmatically.

Ak10147
  • 103
  • 1
  • 7

3 Answers3

0

Try using the code in https://stackoverflow.com/a/1109108/1904479. Hope you are not testing it in Android version 4.1.

Community
  • 1
  • 1
Kailas
  • 6,486
  • 3
  • 41
  • 61
0

KeyEvent.KEYCODE_HOME can NOT be intercepted. You can hide the keypad inputmgr.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0); in onStop() method of your activity.

It does not require token from focused view editText.

Pr38y
  • 1,495
  • 13
  • 20
0

please use this method to hide soft keyboard.

public static void hideSoftKeyboard(Activity context) {
        InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (inputManager != null)
        inputManager.hideSoftInputFromWindow(context.getWindow().getDecorView().getApplicationWindowToken(), 0);
        context.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    }
bhavesh kaila
  • 756
  • 5
  • 25