黄油刀自定义视图解除绑定 [英] Butterknife custom view unbind

查看:262
本文介绍了黄油刀自定义视图解除绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拨打电话的最佳做法是:-

What's the best practice for calling : -

Butterknife.unbind()

请在自定义的Android视图中查看?

in a custom Android view please?

推荐答案

是的,onDetachedFromWindow NJ's中提到的正确函数答案,因为这是视图不再具有绘制图面的地方.

Yes, onDetachedFromWindow is the right function as mentioned in NJ's answer because this is where view no longer has a surface for drawing.

但是答案中错误地提到了用法.正确的方法包括在onFinishInflate():

But the usage is incorrectly mentioned in the answer. The right approach involves binding in onFinishInflate():

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    unbinder = ButterKnife.bind(this);
}

并在onDetachedFromWindow中解除绑定:

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    // View is now detached, and about to be destroyed
    unbinder.unbind();
}

这篇关于黄油刀自定义视图解除绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆