1

I was hoping to get the answer for this, I have tried very much to dismiss the popup window when I click outside, but it is not dismissing, anybody know why? Also it is not going back when I click back button.

public void onButtonPopup (View target) {
       // Make a View from our XML file
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int height = size.y; 

        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.samplescreens, (ViewGroup) findViewById(R.id.closeLayout));


        pwindo = new PopupWindow(layout, width-40, height-(height/4), true);
        pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

        pwindo.update();
        pwindo.setOutsideTouchable(true);
    }
public void onButtonInPopup (View target) {
        //back_dim_layout.setVisibility(View.GONE);
        pwindo.dismiss();
    }
stallianz
  • 176
  • 1
  • 17

2 Answers2

0

One problem from your code is you've written pwindo = new PopupWindow(layout, width-40, height-(height/4), true); in which forth parameter is true i.e. keep popup window focusable. This is the mistake, as though you say pwindo.setOutsideTouchable(true); you've already defined that popup window should be focusable. Make that forth parameter to false. Still if you're not able to dismiss it, then before dismissing a popup like pwindo.dismiss() write this line, pwindo.setBackgroundDrawable(new BitmapDrawable(getResources()));.

Hope it helps you.

imthegiga
  • 1,126
  • 8
  • 13
0

Finally solved it! Changed the order:

pwindo = new PopupWindow(layout, width-40, height-(height/4), true);

        pwindo.setOutsideTouchable(true);
        pwindo.setTouchable(true);
        pwindo.setBackgroundDrawable(new BitmapDrawable());
        pwindo.setTouchInterceptor(customPopUpTouchListenr);

    pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

it works now

stallianz
  • 176
  • 1
  • 17