popup - Can android PopupWindow show another PopupWindow? -
can android popupwindow show popupwindow? how many popupwindow can opened in same time? one?
the first popupwindow displayed normally. on button click (which in first popupwindow contentview) having exception:
08-13 16:28:38.682: error/androidruntime(11760): fatal exception: main android.view.windowmanager$badtokenexception: unable add window -- token android.view.viewrootimpl$w@41286250 not valid; activity running? @ android.view.viewrootimpl.setview(viewrootimpl.java:600) @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:313) @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:215) @ android.view.windowmanagerimpl$compatmodewrapper.addview(windowmanagerimpl.java:140) @ android.view.window$localwindowmanager.addview(window.java:537) @ android.widget.popupwindow.invokepopup(popupwindow.java:992) @ android.widget.popupwindow.showasdropdown(popupwindow.java:901) @ org.example.qberticus.quickactions.betterpopupwindow.showlikepopdownmenu(betterpopupwindow.java:159) @ org.example.qberticus.quickactions.betterpopupwindow.showlikepopdownmenu(betterpopupwindow.java:129) @ name.antonsmirnov.android.popup.ui.mainactivity$1$1.run(mainactivity.java:44) @ android.app.activity.runonuithread(activity.java:4170) @ name.antonsmirnov.android.popup.ui.mainactivity$1.onclick(mainactivity.java:42) @ android.view.view.performclick(view.java:3558) @ android.view.view$performclick.run(view.java:14157) @ android.os.handler.handlecallback(handler.java:605) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4514) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:790) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:557) @ dalvik.system.nativestart.main(native method)
the code is:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); bindcontrols(); initcontrols(); } private button button; private void bindcontrols() { button = (button) findviewbyid(r.id.button); } private void initcontrols() { initbutton(button); } private void initbutton(final button button) { button.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { final betterpopupwindow window = new betterpopupwindow(button); view popupview = createpopupview(); window.setcontentview(popupview); runonuithread(new runnable() { public void run() { window.showlikepopdownmenu(); } }); } }); } private view createpopupview() { view v = layoutinflater.from(mainactivity.this).inflate(r.layout.window, null); button popupbutton = (button) v.findviewbyid(r.id.popupbutton); initbutton(popupbutton); return v; }
after playing i've found that
window.showatlocation(getwindow().getdecorview(), gravity.center, x, y);
works okay, but
window.showasdropdown(getwindow().getdecorview(), gravity.center, x, y);
raises exception! if use showatlocation(view)
view different getwindow().getdecorview()
you'll still have exception.
Comments
Post a Comment