神兵利器--ButterKnife module中使用的坑

问题:如何在module中使用ButterKnife
解决:当前module中的build.gradle添加

apply plugin: 'android-apt'
apply plugin: 'com.jakewharton.butterknife'
dependencies {
    apt "com.jakewharton:butterknife-compiler:$butterknifeVersion"  
    //你的baselibrary包含butterknife
    compile project(':baselibrary')
}  

问题:module中使用ButterKnife无法找到R
解决:以R2.id.xxxx寻找对应的view

 @BindView(R2.id.with_param)
  Button btn;

问题:view点击事件对应不上
解决:R2.id.xxx == R.id.xxx
原因:R2 is only for use inside annotations in library projects but all runtime code should still be using the normal R

 @OnClick({ R2.id.with_param, R2.id.with_interceptor, R2.id.with_service, R2.id.with_url, R2.id.with_no_interceptor })
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.with_param) {
        }
        else if (id == R.id.with_interceptor) {
        }
        else if (id == R.id.with_no_interceptor) {
        }
        else if (id == R.id.with_service) {
        }
    }

Demo:https://github.com/zhujian1989/mf

ps:持续记录使用中的问题

你可能感兴趣的:(神兵利器--ButterKnife module中使用的坑)