Code example for PopupWindow

Methods: setTouchInterceptor

     * @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() {
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                    return true; 
                return false; 
Stop searching for code, let great code find you!  Add Codota to your java IDE