7

I was hoping to get an answer to my problem I have at the moment.

I have a class which extends popup window. It works fine except I don't want the window to dismiss when I click outside of the window.

At the moment I have setOutsideTouchable(false); but this just stops events outside the window, it still dismisses the popup.

A dialog has setCanceledOnTouchOutside(false), is there something similar I can use?

Thanks

Joss Stuart
  • 1,856
  • 1
  • 17
  • 19
  • Here's my answer[1]! And the question is [question]. [1]: http://stackoverflow.com/questions/10406339/avoiding-popupwindow-dismissal-after-touching-outside/30586418#30586418 [question]:http://stackoverflow.com/questions/10406339/avoiding-popupwindow-dismissal-after-touching-outside – lulalagulu Jun 02 '15 at 02:40

2 Answers2

8

Ok so fixed in the end.

First made the main layout which the popup sits on a relative layout. Then placed a full screen blank layout on top which I made invisible and transparent.

Then show when the popup is shown, set the full screen panel visible with setVisibility(View.VISIBLE); and hide when popup is hidden with setVisibility(View.GONE);

Also need to return true from an on touch listener for the layout with (To stop touch events passing back to the main layout):

blocker.setOnTouchListener(new OnTouchListener() { 
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});

And give the popup window the properties:

setTouchable(true);
setOutsideTouchable(false);

Cheers

Joss Stuart
  • 1,856
  • 1
  • 17
  • 19
0

What are you using this PopupWindow for? It sounds like you use it in a more Dialog-ish way.

That being said you'll probably have to look into using setTouchInterceptor and then creating your own OnTouchListener which you will use to check where the touch was performed (on the Popup or not).

kaspermoerch
  • 16,127
  • 4
  • 44
  • 67
  • Hi, I am using the popup window with a carousel and several linear layouts inside. It seems to work best for what I need to do aside from this issue I have. – Joss Stuart Dec 02 '11 at 14:00