在项目开发过程中,需要经常性的涉及到对象的查找与使用,以及业务数据在对象上的展示等需求,
为解决布局文件与类文件之前的关联关系,有二种方式
方法一: DataBing
------------------------------------------------------------------------------------------------------------------------------------
01. 使用配置
在 build.gradle 文件中,android 项之下,开启数据绑定功能
dataBinding {
enabled true
}
02.将常规布局文件转换为数据绑定布局(在布局上 alt + 回车键 )
03. 完成上述操作后,系统会自动生成一个关联的绑定类
如果布局文件为: activity_simple.xml (X_Y.xml)
则生成的绑定类为: ActivitySampleBinding; (XYBinding)
04. 使用
第二种方法:ButterKnife
-----------------------------------------------------------------------------------------------------------------------------------------
01.App下 build.gradle 中对包的引用
//黄油刀
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
02. 使用