Q: Android: Hiding or destroy view when onPause() is called Hi am using a customkeyboard view in my fragment. when ever user taps on the edit text am shwoing this view
insideEdit.setOnTouchListener(new OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event) {

                    mKeyboardViewTolerance = new CustomKeyboard(getActivity(), R.id.keyboardviewtolerance, R.xml.keyboard_layout);
                    mKeyboardViewTolerance.showCustomKeyboard(insideEdit);
                    insideEdit.setInputType(InputType.TYPE_NULL);
                    return false;
                }
            });

when ever user switches to other fragments and comes to the same fragment and  taps the edittext the view is not rendering. I can see the view is there but the view is not visible on screen.
I tried hiding it in OnPause() but still the view is not visible
 @Override
    public void onPause() {
         if(mKeyboardViewTolerance != null && mKeyboardViewTolerance.isCustomKeyboardVisible()){

                mKeyboardViewTolerance.hideCustomKeyboard();
            }
}


A: Try using focus listener on EditText.

A: Use this code, it will solve your problem:
 View view = this.getCurrentFocus();
 if (view != null) {
   InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            mInputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

