Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

popupWindow.setOnDismissListener triggers popupmenu again

Below is my code, menu - ImageView menubottom - ImageView My requirement is to display the menubottom image when the popup is shown.

menu.setOnClickListener(new OnClickListener() 
    {   
        public void onClick(View v) 
        {View layout=(View)getLayoutInflater().inflate(R.layout.navigationbar, null);
        popupWindow = new PopupWindow(getApplicationContext());
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setContentView(layout);
        popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
        popupWindow.setWidth(swidth);
        popupWindow.setFocusable(false);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setAnimationStyle(-1);

            if(x==1)
            {   popupWindow.showAsDropDown(menubottom);
                menubottom.setVisibility(View.VISIBLE);
                x=0;                    
            }
            else
            {   
                popupWindow.dismiss();
                popupWindow=null;           
            }
            popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

                @Override
                public void onDismiss() {
                    // TODO Auto-generated method stub
                    menubottom.setVisibility(View.INVISIBLE);   
                    x=1;

                }
            });

        }

}

ISSUE: When the menu button is clicked popup shows and menubottom shown. On pressing menu again, the popupmenu is hidden and then shown again.

On pressing outside the popupmenu, its working as expected(popup and menubottom is hidden)

I think, setOnDismissListener triggers the menu.setOnClickListener again. Thanks in Advance.

like image 858
Vignesh Avatar asked Nov 01 '22 04:11

Vignesh


1 Answers

i think the problem is after pop up, because menu button is outside popupwindow, popupwindow get dismissed and menu button's onclick trigger again. so may be you can do something like this (initially x=1)

menu.setOnClickListener(new OnClickListener() 
{   
    public void onClick(View v) 
    {View layout=(View)getLayoutInflater().inflate(R.layout.navigationbar, null);
    popupWindow = new PopupWindow(getApplicationContext());
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.setContentView(layout);
    popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
    popupWindow.setWidth(swidth);
    popupWindow.setFocusable(false);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setAnimationStyle(-1);

      /*  if(x==1)
        {   popupWindow.showAsDropDown(menubottom);
            menubottom.setVisibility(View.VISIBLE);
            x=0;                    
        }
        else
        {   
            popupWindow.dismiss();
            popupWindow=null;           
        } */

        if(x==0) {
            x=1;
        } else {
        popupWindow.showAsDropDown(menubottom);
            menubottom.setVisibility(View.VISIBLE);

        }
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            @Override
            public void onDismiss() {
              // TODO Auto-generated method stub
                menubottom.setVisibility(View.INVISIBLE);   
                x=0;

            }
        });

    }

}

like image 132
Farhan C K Avatar answered Nov 17 '22 23:11

Farhan C K