butterknife icon indicating copy to clipboard operation
butterknife copied to clipboard

OnClick method is not work when used the R2.id.xxx.

Open tqlmorepassion opened this issue 5 years ago • 4 comments

butterKnifePlugin--10.1.0 Gradle 3.4.2

We found that we did not know what circumstances would cause this problem, but we did encounter it several times. Once encountered, only killing the process will return to normal.

just like:

@OnClick(R2.id.tv_close) public void onViewClicked() { onBackPressed(); }

tqlmorepassion avatar May 20 '20 03:05 tqlmorepassion

Can you provide a sample that reproduces the issue? What does the generated code look like?

JakeWharton avatar May 20 '20 03:05 JakeWharton

We did not know how to reproduces the issue, but we received feedback from our customers several times. And our QA faced it today, I had debugged it, it seems like the @OnClick(R2.id.tv_close) did not work as well. It works well most time, but we did not know how to reproduces it. So I had to update the version to 10.2.1.

The generated code is

`public class NavigationBar_ViewBinding implements Unbinder { private NavigationBar target;

private View view7f0b0080;

private View view7f0b0085;

private View view7f0b0054;

@UiThread public NavigationBar_ViewBinding(NavigationBar target) { this(target, target); }

@UiThread public NavigationBar_ViewBinding(final NavigationBar target, View source) { this.target = target;

View view;
target.mTvNavigationTitle = Utils.findRequiredViewAsType(source, R.id.m_tv_navigation_title, "field 'mTvNavigationTitle'", TextView.class);
view = Utils.findRequiredView(source, R.id.m_iv_navigation_back, "field 'mIvNavigationLeft' and method 'onViewClicked'");
target.mIvNavigationLeft = Utils.castView(view, R.id.m_iv_navigation_back, "field 'mIvNavigationLeft'", ImageView.class);
view7f0b0080 = view;
view.setOnClickListener(new DebouncingOnClickListener() {
  @Override
  public void doClick(View p0) {
    target.onViewClicked(p0);
  }
});
target.tvLeft = Utils.findRequiredViewAsType(source, R.id.mLeftText, "field 'tvLeft'", TextView.class);
target.viewStup = Utils.findRequiredViewAsType(source, R.id.view_stup, "field 'viewStup'", ViewStub.class);
view = Utils.findRequiredView(source, R.id.m_tv_navigation_right_text, "field 'mTvNavigationRightText' and method 'onViewClicked'");
target.mTvNavigationRightText = Utils.castView(view, R.id.m_tv_navigation_right_text, "field 'mTvNavigationRightText'", TextView.class);
view7f0b0085 = view;
view.setOnClickListener(new DebouncingOnClickListener() {
  @Override
  public void doClick(View p0) {
    target.onViewClicked(p0);
  }
});
target.mIvOne = Utils.findRequiredViewAsType(source, R.id.iv_right_one, "field 'mIvOne'", ImageView.class);
target.mivTwo = Utils.findRequiredViewAsType(source, R.id.iv_right_two, "field 'mivTwo'", ImageView.class);
target.mIvThree = Utils.findRequiredViewAsType(source, R.id.iv_right_three, "field 'mIvThree'", ImageView.class);
target.mIvNavigationLeftBg = Utils.findRequiredViewAsType(source, R.id.m_iv_navigation_bg, "field 'mIvNavigationLeftBg'", ImageView.class);
view = Utils.findRequiredView(source, R.id.fl_back, "method 'onViewClicked'");
view7f0b0054 = view;
view.setOnClickListener(new DebouncingOnClickListener() {
  @Override
  public void doClick(View p0) {
    target.onViewClicked(p0);
  }
});

}

@Override @CallSuper public void unbind() { NavigationBar target = this.target; if (target == null) throw new IllegalStateException("Bindings already cleared."); this.target = null;

target.mTvNavigationTitle = null;
target.mIvNavigationLeft = null;
target.tvLeft = null;
target.viewStup = null;
target.mTvNavigationRightText = null;
target.mIvOne = null;
target.mivTwo = null;
target.mIvThree = null;
target.mIvNavigationLeftBg = null;

view7f0b0080.setOnClickListener(null);
view7f0b0080 = null;
view7f0b0085.setOnClickListener(null);
view7f0b0085 = null;
view7f0b0054.setOnClickListener(null);
view7f0b0054 = null;

} }`

tqlmorepassion avatar May 20 '20 03:05 tqlmorepassion

Maybe the same problem with #1511 , the DebouncingOnClickListener did not work.

tqlmorepassion avatar May 20 '20 04:05 tqlmorepassion

We saw this too, kapt stubs in some cases inlined the constant value rather than the qualified reference, seemingly only on the OnClick-annotated methods. Was a good forcing function to move to listeners in preparation for viewbinding

    @butterknife.BindView(value = com.Slack.R2.id.toolbar)
    public androidx.appcompat.widget.Toolbar toolbarNewName3;

    @butterknife.OnClick(value = {5496})
    public final void onSendMagicLinkClicked() {
    }

ZacSweers avatar Sep 22 '20 09:09 ZacSweers