¿Es posible descartar una ventana emergente de su controlador de botones en una actividad diferente?

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 despedir() 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 despedir() ¿método?

Gracias de antemano!

preguntado el 01 de febrero de 12 a las 03:02

2 Respuestas

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 abstracty 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).

Respondido 01 Feb 12, 14:02

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

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 ;) - William

for Popup window there : duplicate Ventana emergente 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) ha sido ejecutado.

contestado el 23 de mayo de 17 a las 15:05

I'm sorry but I really don't understand what you're getting at or how this relates to my question. - user316117

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.