1

In My Layout there is a EditText for search and there is a list below the EditText.Now I'm inflating this layout in a PopupWindow . Now My problem is

1)If I set the PopupWindow focusable true , then all the places other than the PopupWindow Layout becomes non clickable.So I can not dismiss the window by clicking outside or by clicking on the back button of the device

2)If I set the PopupWindow focusable false , then the Popupwindow open and close is perfect but soft keyboard is not becoming visible on tap of the EditText

LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            // Inflate the view from a predefined XML layout View layout = inflater.inflate(R.layout.popup_layout, null);
mPopUpWindow= new PopupWindow(layout,0, mScreenHeight - 100, false);
mPopUpWindow.setBackgroundDrawable(null);
mPopUpWindow.setOutsideTouchable(true);
mPopUpWindow.setTouchInterceptor(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // TODO Auto-generated method stub
                    if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                        mPopUpWindow.dismiss();

                    }
                    return false;
                }
            });

final InputMethodManager inputMgr = (InputMethodManager) MainApplication.getContext().getSystemService(
                    Context.INPUT_METHOD_SERVICE);
inputMgr.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_SEARCH) {

inputMgr.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                                InputMethodManager.HIDE_NOT_ALWAYS);

                        return true;
                    }
                    return false;
                }
            });
chiranjib
  • 5,288
  • 8
  • 53
  • 82
  • Could you please paste some code here, so we can see where the problem might be or give you a hint on how to overcome it? – g00dy Jun 26 '13 at 12:08

2 Answers2

0

Simply use this

View popupView= getLayoutInflater().inflate(R.layout.popupmenu,null);
                PopupWindow popup = new PopupWindow(popupView, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,true);
                popup.setBackgroundDrawable(new BitmapDrawable());
                popup.setOutsideTouchable(true);
                popup.showAsDropDown(view);
                popup.update();

The main point is that PopUpWindow can't be null. See this answer here

Community
  • 1
  • 1
Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
0

Add the three lines in the code:

popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAsDropDown(ivmainmenu);

And,the show of the popupWindow must be called in the end.

Maoran Bian
  • 53
  • 1
  • 7