0

I didn't architect this, but here's the situation : there is a PopupWindow with a button in it. The button handler is in a different activity from the Activity that created the PopupWindow. I want to know if there's a way to use the View param to the button handler to access the PopupWindow to have it dismiss() itself when I tap the button.

So far I've been able to use a series of getParent()'s to iterate up to the containing PopupWindow. But when I do it says it's a "PopupWindow$PopupViewContainer" (PopupWindow itself is not derived from View; it's derived from Object)

Is there any way I can use this to access the actual PopupWindow so I can call its dismiss() method?

Thanks in advance!

user316117
  • 7,971
  • 20
  • 83
  • 158

2 Answers2

0

for Popup window there : duplicate Popup Window just see the solution for this.

and if you are talking about the dismiss();

public void dismiss ()

Dispose of the popup window. This method can be invoked only after showAsDropDown(android.view.View) has been executed.

Community
  • 1
  • 1
NovusMobile
  • 1,813
  • 2
  • 21
  • 48
0

I didn't architect this...

If you're working on it, then I suggest you (slightly) change the architecture to make it right.

Here is what I suggest: (I suppose the code for the handler is in another activity because these two activities can have the popup window?)

  • Extract a base superclass for all the activities that can have the popup window, (make it abstract, and extends Activity, and all your concrete activities will extend that class), and put the handler code in this one.

  • Keep a reference to the parent PopupWindow in that base activity, so you can always access it from the handler, or from anything else that might need it (keep that reference private to preserve encapsulation).

Guillaume
  • 22,694
  • 14
  • 56
  • 70
  • The code owners are really close a release deadline and don't want any architectural changes. My marching orders are 'do it within the button handler IF it can be done there, else defer this to a future release.' It's not obvious to me whether there's a way to do this in the handler so I'm just asking so I can decide whether to defer it. Thanks again. – user316117 Feb 01 '12 at 14:30
  • OK, I get it - So I don't know a "direct" way to get to the parent window, your way of using a series of getParent is probably a good try. Good luck with that ;) – Guillaume Feb 01 '12 at 14:58