亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

android - AS中Module中沒法使用Butterknife.有什么好的替代?

瀏覽:98日期:2024-09-07 11:29:25

問題描述

說是Module中的R文件下的id不是final的。然后Butterknife就不行。。。估計別的注解類型的也不好使吧。。。于是乎有什么辦法么。。

詳見:https://github.com/JakeWharton/butterknife/issues/100

以下是作者JakeWharton在14年12月的原話。。。

Yes this is not supported. This is a tradeoff between ease-of-use and what I tolerate as a sane API.

The only way to accomplish something like this is to allow string values like this:

@InjectView(name = 'content_frame') protected FrameLayoutcontentFrame; The downside’s to this are:

The downside’s to this are:

It’s not rename-safe or compile-safe (kind of). If you open the layout XML for this and do an IDE-backed rename operation it will not catch this string and update it. It also means you can (technically) compile the above code if there is no content_frame ID that exists. Now the compilation will eventually fail because the generated code will become invalid.

It’s hard to know what R class to reference in the generated code, especially when you take into consideration the fact that you can use references to IDs that exist in libraries that you are referencing.

It forces us to have defaults for both the value and name properties on each annotation which means you can write @InjectView Foo foo and Butter Knife will have to fail the builder rather than javac.

Because of these facts, I have chosen not to support library projects.

One way that this could potentially be solved is to use a Gradle plugin rather than an annotation processor. I don’t have the time to explore something like that for a few months though.

問題解答

回答1:

Android Studio Prettify

這個插件自動生成findViewById等內容,你可以試試。 你說Butterknife不能用,應該是你用錯了吧,你仔細看看是不是用錯了。

回答2:

module中好像也沒看到別的,還是直接使用findViewById吧

回答3:

現在基本不用butterknife了,直接封裝一個方法在BaseActivity或BaseFragment

//BaseActivitypublic <T extends View> T $(@IdRes int resId){ return (T)super.findViewById(resId);}//BaseFragmentpublic <T extends View> T $(View layoutView, @IdRes int resId){ return (T)layoutView.findViewById(resId);}//使用TextView tvName=$(R.id.tv_name);回答4:

這個也行,功能比較多https://github.com/excilys/androidannotations

回答5:

最好使用系統自帶的findviewyid來查找id,第三方的工具之間使用會存在沖突

回答6:

RoboGuice?或者android annotation?

回答7:

android - AS中Module中沒法使用Butterknife.有什么好的替代?

相關文章:
主站蜘蛛池模板: 精品无人区乱码一区二区三区手机 | 欧美草逼网 | 国产视频国产 | 桃花阁成人网在线观看 | 黄色免费在线观看网址 | 九九成人 | 国产精品亚洲欧美日韩区 | 一级黄色在线观看 | 免费看的黄色小视频 | 欧美日韩顶级毛片www免费看 | 99国产精品一区二区 | 色综合综合色 | 高清视频黄色录像免费 | 欧美一级淫片漂亮的老师 | 国产成人精品影院狼色在线 | 在线观看一区二区三区视频 | 免费大片a一级一级 | 欧美日韩一级大片 | 久久99精品久久久久久首页 | 国产精品一区二区欧美视频 | 人人婷婷色综合五月第四人色阁 | 亚洲欧美一区二区久久 | 7788成年网站免费观看 | 亚洲欧美一区二区三区二厂 | 在线视频毛片 | 欧美日本俄罗斯一级毛片 | 亚洲国产情侣一区二区三区 | 亚洲精品成人一区二区www | 麻豆精品国产免费观看 | 国产a一级毛片含羞草传媒 国产a三级三级三级 | 日韩在线视频一区二区三区 | 免费黄色欧美视频 | 国产精品久久久久久福利漫画 | 国产精品网红女主播久久久 | 最新精品视频在线观看 | 成人精品在线视频 | sese综合| 在线观看福利视频在线观看 | 精品视频一区二区观看 | 免费观看欧美性生 | 1024免费观看|