神兵利器--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:持续记录使用中的问题

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容