The documentation states that PopupWindow
will be informed of touch events outside of its window when
setOutsideTouchable(boolean touchable)
is set to true.
How is popupwindow informed? I don't see any listener like setOnOutsideTouchListener
etc to receive that information.
Example
PopupWindow popup = new PopupWindow();
popup.setOutsideTouchable(true);
//now what..how to receive those touch outside events?
Thanks.
try to use setTouchInterceptor like the following snipt of code
popup.setTouchInterceptor(new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_OUTSIDE)
{
popup.dismiss();
return true;
}
return false;
}
});
also don't forget to set thew following flag:
popup.setOutsideTouchable(true);
When you touch outside the PopupWindow, OnDismissListener is triggered as touching outside window dismisses the window by default, so you can set OnDismissListener on popupWindow to listen to touch outside the window.
popup.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
//Do Something here
}
});
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