我創建了彈出窗口不能排除popUpWindow
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);
}
和overrided後退按鈕按下dissmis
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);
}
爲u能理解我 - 我想dissmis /隱藏popupwindow當我按下後退按鈕但現在我得到如下因素錯誤的:(
05-12 12:27:15.373: ERROR/WindowManager(1259): Activity myClass.com.myClass has leaked window [email protected] that was originally added here
05-12 12:27:15.373: ERROR/WindowManager(1259): android.view.WindowLeaked: Activity myClass.com.myClass has leaked window [email protected] 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)
有人能幫助我,告訴如何糾正dismis彈出w ^母雞我按backButton?
p.s.對不起我的英語不好,希望你能理解我。問候,彼得。
使用對話框可以做同樣的事情,試試吧,很容易管理 – 2011-05-13 03:50:02
我在這裏找到了解決方案 - > http://stackoverflow.com/questions/3121232/android-popup-window-dismissal – Peter 2011-05-13 09:43:35