Code example for PopupWindow

Methods: setTouchInterceptor

0
     * @param anchor 
     *            the view that the BetterPopupWindow will be displaying 'from' 
     */ 
    public BetterPopupWindow(View anchor) {
        this.anchor = anchor;
        this.window = new PopupWindow(anchor.getContext());
 
        // when a touch even happens outside of the window 
        // make the window go away 
        this.window.setTouchInterceptor(new OnTouchListener() {
            @Override 
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                    BetterPopupWindow.this.window.dismiss();
                    return true; 
                } 
                return false; 
            } 
        }); 
 
        this.windowManager = (WindowManager) this.anchor.getContext()