无法解雇popUpWindow

时间:2011-05-12 12:34:59

标签: java android popupwindow

我创建了我的popUp窗口

 public void myPopUp()
    {

        LinearLayout myView = new LinearLayout(getApplicationContext());
         pw = new PopupWindow(getApplicationContext());
         pw.setContentView(myView);
         myView.setBackgroundColor(Color.WHITE);
         pw.setWidth(curWidth-100);
         pw.setHeight(curHeight-100);
         pw.showAtLocation(background, Gravity.CENTER, 0, 0);
   }

并且压倒了backButton被迫解散

public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            getNewWH();
               middle.removeView(bb);
            if(statusBG==2)
            {
                 log("statusBG = "+statusBG);
                 showFeed();
                 statusBG=1;
            }
            else
            if(statusBG==1)
                { 
                    finish();
                }
            else
            if (pw.isShowing()) {
                 log("here again");
                pw.dismiss();
                log("here");

            }
          return true;  
        }
        return super.onKeyDown(keyCode, event);
    }

你可以理解我 - 当我按下backButton但我现在得到以下错误时,我想要dissmis / hide popupwindow :(

05-12 12:27:15.373: ERROR/WindowManager(1259): Activity myClass.com.myClass has leaked window android.widget.PopupWindow$PopupViewContainer@44ec28a8 that was originally added here
05-12 12:27:15.373: ERROR/WindowManager(1259): android.view.WindowLeaked: Activity myClass.com.myClass has leaked window android.widget.PopupWindow$PopupViewContainer@44ec28a8 that was originally added here
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.view.ViewRoot.<init>(ViewRoot.java:247)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.widget.PopupWindow.invokePopup(PopupWindow.java:828)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.widget.PopupWindow.showAtLocation(PopupWindow.java:688)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at myClass.com.myClass.myPopUp(myClass.java:743)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at myClass.com.myClass$15.onClick(myClass.java:724)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.view.View.performClick(View.java:2408)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.view.View$PerformClick.run(View.java:8816)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.os.Handler.handleCallback(Handler.java:587)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.os.Looper.loop(Looper.java:123)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at java.lang.reflect.Method.invokeNative(Native Method)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at java.lang.reflect.Method.invoke(Method.java:521)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-12 12:27:15.373: ERROR/WindowManager(1259):     at dalvik.system.NativeStart.main(Native Method)

当我按下backButton时,任何人都可以帮助我并告诉我如何纠正dismis弹出窗口吗?

P.S。抱歉我的英语不好,希望你能理解我。问候,彼得。

2 个答案:

答案 0 :(得分:2)

用于解除PopupWIndow而不是root活动或者通过backpress查看是设置焦点。 popupWindow.setFocusable(真);

弹出窗口没有焦点,所以当按下后面时,它会关闭主要活动,因为焦点在主要活动上。

答案 1 :(得分:0)

请勿使用getApplicationContext()代替传递上下文或此。

LinearLayout myView = new LinearLayout(context or this);