神兵利器--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:持續記錄使用中的問題

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容