Takeshi Tokugawa YD
Takeshi Tokugawa YD

Reputation: 1001

onClickListener for the touch outside of the popupWindow

From the question Issue dismissing popup window I learned how to hide the popupWindow (before this, popupWindow.dismiss(); in the following code didn't work).

private void initFAB(){
        fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {

        boolean showPopupWindow = false;

        public void onClick(View view) {

            LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
                    .getSystemService(LAYOUT_INFLATER_SERVICE);
            View popupWindowContent = layoutInflater.inflate(R.layout.popup_window_content, null);
            final PopupWindow popupWindow = new PopupWindow(popupWindowContent,
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            popupWindow.setOutsideTouchable(true);

            if (!showPopupWindow){
                rotateFabForward();

                View.OnClickListener onClickListener = new View.OnClickListener() {
                    public void onClick(View view) {
                        //...
                    }
                };

                // ...

                popupWindow.showAtLocation(fab, Gravity.END | Gravity.BOTTOM, 50, 400);
                showPopupWindow = true;
            }
            else{
                rotateFabBackward();
                popupWindow.dismiss();
                showPopupWindow = false;
            }
        }
    });
}

Now, when I click outside the popupWindow and it disappears, FloatingActionButton don't rotates back (it has + icon when the popupWindow is hidden and rotates 45 degress and icon becomes × when the popupWindow is visible).

Any listeners that allows to registry the touch outside the popupWindow and execute rotateFabBackward()?


P. S. Also, thanks for the answer on this question about FAB rotation.

Upvotes: 0

Views: 318

Answers (1)

ToanNV
ToanNV

Reputation: 56

you should add onDismiss listener like that

popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
    @Override
    public void onDismiss() {
        rotateFabBackward();
        showPopupWindow = false;
        // end may TODO anything else                   
    }
});

Upvotes: 1

Related Questions