1

这里泄漏了什么,我不明白。

 06-07 17:04:50.319: E/WindowManager(23232): Activity com.test.MainActivity has leaked window android.widget.LinearLayout@41ab4238 that was originally added here
06-07 17:04:50.319: E/WindowManager(23232): android.view.WindowLeaked: Activity com.test.MainActivity has leaked window android.widget.LinearLayout@41ab4238 that was originally added here
06-07 17:04:50.319: E/WindowManager(23232):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:403)
06-07 17:04:50.319: E/WindowManager(23232):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
06-07 17:04:50.319: E/WindowManager(23232):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
06-07 17:04:50.319: E/WindowManager(23232):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
06-07 17:04:50.319: E/WindowManager(23232):     at android.view.Window$LocalWindowManager.addView(Window.java:537)
06-07 17:04:50.319: E/WindowManager(23232):     at android.widget.PopupWindow.invokePopup(PopupWindow.java:992)
06-07 17:04:50.319: E/WindowManager(23232):     at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:901)
06-07 17:04:50.319: E/WindowManager(23232):     at com.test.MainActivity.onClick(MainActivity.java:91)

我的代码如下

活动课

@Override
public void onClick(View v) {

        LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
        View popupView = layoutInflater.inflate(R.layout.popup, null);  
        popupWindow = new SettingsPopupWindow(popupView, 150, 300);  
        popupWindow.showAsDropDown(btnOpenPopup, 0, 0);
}

protected void initMenuButtonPopup()
{
    btnOpenPopup = (Button)findViewById(R.id.menuButton);
    btnOpenPopup.setOnClickListener(this);

}

弹出类

public class SettingsPopupWindow extends PopupWindow implements OnClickListener{
View vw;

@Override
public void onClick(View v) {
    dismiss();

}

public SettingsPopupWindow(View contentView, int width, int height)
{
    super(contentView, width, height);
    this.vw = contentView;
    Button btnDismiss = (Button)vw.findViewById(R.id.dismiss);
    btnDismiss.setOnClickListener(this);

}

}

4

1 回答 1

3

dismiss你必须PopUpWindow在同一个类中,其中包含它的引用。所以把你的onClick行为移到Activity.

于 2013-06-07T11:58:25.710 回答