如何使用黄油刀';android中显示对话框函数中的s Bind()

如何使用黄油刀';android中显示对话框函数中的s Bind(),android,butterknife,Android,Butterknife,这是我的showDialog函数,当有人单击活动中的按钮时,它会被调用 private void showCouponCodeDialog() { final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialoge_apply_coupon); dialog.setTitle(R.string.coupon_code); final ProgressBar progres

这是我的showDialog函数,当有人单击活动中的按钮时,它会被调用

private void showCouponCodeDialog() {

    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.dialoge_apply_coupon);
    dialog.setTitle(R.string.coupon_code);

    final ProgressBar progressBar = (ProgressBar) dialog.findViewById(R.id.progressBar);
    progressBar.setVisibility(View.GONE);
    Button btnApplyCoupon = (Button) dialog.findViewById(R.id.btnApplyCoupon);
    btnApplyCoupon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            progressBar.setVisibility(View.VISIBLE);

        }
    });
    dialog.show();
}
当我这样做的时候

@Bind(R.id.progressBar) ProgressBar progressBar;
它给出了不适用于局部变量的错误@Bind

这个很好用

final ProgressBar progressBar = (ProgressBar) dialog.findViewById(R.id.progressBar);

在这种情况下如何使用butterknief的Bind()?

使用
butterknief
您可以使用以下绑定方法:

Butterknife.bind(Dialog dialog)


第二个更好,正如它所建议的,在哪里(在哪个类中)绑定是有效的。请记住,这些函数返回
Unbinder
,当对话框被破坏时,解除绑定非常重要,否则可能会发生内存泄漏。

使用
Butterknife
可以使用以下绑定方法:

Butterknife.bind(Dialog dialog)


第二个更好,正如它所建议的,在哪里(在哪个类中)绑定是有效的。请记住,这些函数返回
Unbinder
,当对话框被破坏时,解除绑定非常重要,否则可能会发生内存泄漏。

或者,您可以将
progressBar
声明为字段而不是局部变量。但progreeBar不是活动的一部分。但是R.layout.dialoge\u apply\u优惠券的pert是否正确。您还必须将视图与
Butterknife
context
绑定。或者,您可以将
progressBar
声明为字段而不是局部变量。但progreeBar不是活动的一部分。但是R.layout.dialoge_apply_优惠券的pert是否正确。您还必须将视图与
Butterknife
上下文绑定