1
これは私のshowDialog関数で、誰かがアクティビティのボタンをクリックしたときに呼び出されます。私はandroidのshow dialog関数でbutterknifeのBind()を使用する方法
@Bind(R.id.progressBar) ProgressBar progressBar;
を行う際
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できます。
これは問題なく動作します。
この場合、butterkniefのBind()を使用するにはどうすればよいですか? (どのクラスで)バインドが保留されている場所、それが示唆するように、第2の1が優れている
Butterknife.bind(Dialog dialog)
または
Butterknife.bind (@NonNull Object target, @NonNull Dialog source)
:Butterknife
を使用して
また、 'progressBar'をローカル変数の代わりにフィールドとして宣言することもできます。 –
しかし、progreeBarはアクティビティの一部ではありません。しかし、R.layout.dialoge_apply_couponのpertです。 –
あなたのビューを 'Butterknife'でも' context'でバインドする必要があります – rookieDeveloper