色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:124日期: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等內(nèi)容,你可以試試。 你說Butterknife不能用,應(yīng)該是你用錯了吧,你仔細(xì)看看是不是用錯了。

回答2:

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

回答3:

現(xiàn)在基本不用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:

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

回答6:

RoboGuice?或者android annotation?

回答7:

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

相關(guān)文章:
主站蜘蛛池模板: 五月激激激综合网色播免费 | 男人的天堂精品国产一区 | 久久久久久一级毛片免费无遮挡 | 亚洲精品国产一区二区图片欧美 | 亚洲性视频网站 | a黄视频 | 国内成人免费视频 | 女仆色在线 | 中文字幕免费 | 国产91精品一区二区视色 | 美女很黄很黄是免费的·无遮挡网站 | 日本乱人伦毛片 | 日韩伦理一区二区三区 | 免费看特黄特黄欧美大片 | 日本特黄特色 | 九九视频精品在线 | 午夜香蕉成视频人网站高清版 | 国产精品黄网站免费观看 | 欧美极品video粗暴 | 国产成年人在线观看 | 日韩一级a毛片欧美一级 | 精品一区二区三区在线观看 | 曰本aaaaa毛片午夜网站 | 国产成人福利夜色影视 | 亚洲精品欧美精品中文字幕 | 久久久精品影院 | 国产欧美日韩一区二区三区在线 | 香港aa三级久久三级 | 性强烈欧美一级毛片 | 成人涩涩屋福利视频 | 99久久国产免费 - 99久久国产免费 | 国产中文字幕视频在线观看 | 女人扒开双腿让男人捅 | 成人久久网 | 精品一久久香蕉国产二月 | 亚洲精品久久久成人 | 亚洲精品tv久久久久 | 日本成人在线视频网站 | 精品一区二区三区免费毛片爱 | 国产一区二区在线视频播放 | 日韩欧美特级毛片 |