android widget 4x1,com.test活動。MainActivity已經泄露了窗口android.widget.LinearLayout@41ab4238。...

What is the leaking here, I dont understand.

這里漏了什么,我不明白。

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.(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)

My Code is as follows

我的代碼如下。

Activity Class

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

}

Popup class

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);

}

}

}

1 个解决方案

#1

3

You have to dismiss your PopUpWindow in the same class, which holds the reference of it. So move your onClick behavior in the Activity.

您必須在同一個類中忽略您的PopUpWindow,它包含它的引用。所以在活動中移動你的onClick行為。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值