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.
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;
}
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With