Skip to content Skip to sidebar Skip to footer

Keyboard And Popup Window Closes On Backpress

I am working on an android application. In an activity at the bottom of the page, I am showing a popupWindow and replaced the keyboard with this popupwindow. This popupWindow is ha

Solution 1:

add code to hide keyboard inside key listener using onKeyDown() mehod.

        boolean isKeyboardHidden=false;
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
         if (event.getAction() == KeyEvent.ACTION_DOWN) {
           switch (event.getKeyCode()) {
                case  KeyEvent.KEYCODE_BACK;
                       if(!isKeyboardHidden && popupview.isFocused())                                
                         {
                          InputMethodManager imm = 
                                   (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

                          imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

                          isKeyboardHidden=true;
                         }
                return true;                        
          }
         }
        return super.onKeyDown(keyCode, event);
        }

Post a Comment for "Keyboard And Popup Window Closes On Backpress"