<i id='BvAbE'><tr id='BvAbE'><dt id='BvAbE'><q id='BvAbE'><span id='BvAbE'><b id='BvAbE'><form id='BvAbE'><ins id='BvAbE'></ins><ul id='BvAbE'></ul><sub id='BvAbE'></sub></form><legend id='BvAbE'></legend><bdo id='BvAbE'><pre id='BvAbE'><center id='BvAbE'></center></pre></bdo></b><th id='BvAbE'></th></span></q></dt></tr></i><div id='BvAbE'><tfoot id='BvAbE'></tfoot><dl id='BvAbE'><fieldset id='BvAbE'></fieldset></dl></div>

      <tfoot id='BvAbE'></tfoot>

      <legend id='BvAbE'><style id='BvAbE'><dir id='BvAbE'><q id='BvAbE'></q></dir></style></legend>

        <small id='BvAbE'></small><noframes id='BvAbE'>

          <bdo id='BvAbE'></bdo><ul id='BvAbE'></ul>

        android PopupWindow 可以显示另一个 PopupWindow 吗?

        时间:2024-04-14

          <small id='vKfxh'></small><noframes id='vKfxh'>

              <bdo id='vKfxh'></bdo><ul id='vKfxh'></ul>

              <tfoot id='vKfxh'></tfoot><legend id='vKfxh'><style id='vKfxh'><dir id='vKfxh'><q id='vKfxh'></q></dir></style></legend>

                1. <i id='vKfxh'><tr id='vKfxh'><dt id='vKfxh'><q id='vKfxh'><span id='vKfxh'><b id='vKfxh'><form id='vKfxh'><ins id='vKfxh'></ins><ul id='vKfxh'></ul><sub id='vKfxh'></sub></form><legend id='vKfxh'></legend><bdo id='vKfxh'><pre id='vKfxh'><center id='vKfxh'></center></pre></bdo></b><th id='vKfxh'></th></span></q></dt></tr></i><div id='vKfxh'><tfoot id='vKfxh'></tfoot><dl id='vKfxh'><fieldset id='vKfxh'></fieldset></dl></div>
                    <tbody id='vKfxh'></tbody>
                  本文介绍了android PopupWindow 可以显示另一个 PopupWindow 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  android PopupWindow 可以显示另一个 PopupWindow 吗?可以同时打开多少个PopupWindow?只有一个?

                  Can android PopupWindow show another PopupWindow? How many PopupWindow can be opened in the same time? Only one?

                  第一个 PopupWindow 正常显示.但是在单击按钮时(在第一个 PopupWindow 内容视图中)我遇到了一个异常:

                  The first PopupWindow is displayed normally. But on button click (which is in the first PopupWindow contentview) i am having an exception:

                  08-13 16:28:38.682: ERROR/AndroidRuntime(11760): FATAL EXCEPTION: main
                          android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@41286250 is not valid; is your activity running?
                          at android.view.ViewRootImpl.setView(ViewRootImpl.java:600)
                          at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:313)
                          at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
                          at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
                          at android.view.Window$LocalWindowManager.addView(Window.java:537)
                          at android.widget.PopupWindow.invokePopup(PopupWindow.java:992)
                          at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:901)
                          at org.example.qberticus.quickactions.BetterPopupWindow.showLikePopDownMenu(BetterPopupWindow.java:159)
                          at org.example.qberticus.quickactions.BetterPopupWindow.showLikePopDownMenu(BetterPopupWindow.java:129)
                          at name.antonsmirnov.android.popup.ui.MainActivity$1$1.run(MainActivity.java:44)
                          at android.app.Activity.runOnUiThread(Activity.java:4170)
                          at name.antonsmirnov.android.popup.ui.MainActivity$1.onClick(MainActivity.java:42)
                          at android.view.View.performClick(View.java:3558)
                          at android.view.View$PerformClick.run(View.java:14157)
                          at android.os.Handler.handleCallback(Handler.java:605)
                          at android.os.Handler.dispatchMessage(Handler.java:92)
                          at android.os.Looper.loop(Looper.java:137)
                          at android.app.ActivityThread.main(ActivityThread.java:4514)
                          at java.lang.reflect.Method.invokeNative(Native Method)
                          at java.lang.reflect.Method.invoke(Method.java:511)
                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
                          at dalvik.system.NativeStart.main(Native Method)
                  

                  代码是:

                      @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;
                  }
                  

                  推荐答案

                  玩了之后发现

                      window.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, x, y);
                  

                  工作正常,但是

                      window.showAsDropDown(getWindow().getDecorView(), Gravity.CENTER, x, y);
                  

                  引发异常!如果您将 showAtLocation(view) 与任何不同于 getWindow().getDecorView() 的视图一起使用,您仍然会遇到异常.

                  raises exception! If you use showAtLocation(view) with any view different from getWindow().getDecorView() you'll still have an exception.

                  这篇关于android PopupWindow 可以显示另一个 PopupWindow 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何更改弹出项目宽度大小? 下一篇:显示一个 PopupWindow 集中

                  相关文章

                  <legend id='TArig'><style id='TArig'><dir id='TArig'><q id='TArig'></q></dir></style></legend>

                2. <small id='TArig'></small><noframes id='TArig'>

                  <i id='TArig'><tr id='TArig'><dt id='TArig'><q id='TArig'><span id='TArig'><b id='TArig'><form id='TArig'><ins id='TArig'></ins><ul id='TArig'></ul><sub id='TArig'></sub></form><legend id='TArig'></legend><bdo id='TArig'><pre id='TArig'><center id='TArig'></center></pre></bdo></b><th id='TArig'></th></span></q></dt></tr></i><div id='TArig'><tfoot id='TArig'></tfoot><dl id='TArig'><fieldset id='TArig'></fieldset></dl></div>
                  • <bdo id='TArig'></bdo><ul id='TArig'></ul>

                    1. <tfoot id='TArig'></tfoot>