File tree Expand file tree Collapse file tree
app/src/main/java/com/lvfq/code/butterknife/annotation Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,16 +28,22 @@ public static void bind(Activity activity) {
2828
2929
3030 private static void bindView (Activity activity ) throws Exception {
31+ //1 获取字节码对象
3132 Class <? extends Activity > aClass = activity .getClass ();
33+ // 2, 获取所有属性(包括私有属性)
3234 Field [] declaredFields = aClass .getDeclaredFields ();
35+ // 3,遍历所有属性
3336 for (Field declaredField : declaredFields ) {
3437 // 允许暴力反射(可操作 private 修饰属性)
3538 declaredField .setAccessible (true );
3639
3740 BindView annotation = declaredField .getAnnotation (BindView .class );
3841 if (annotation != null ) {
42+ // 4 , 获取注解上的值
3943 int id = annotation .value ();
44+ // 5 , 实例化控件。
4045 View viewById = activity .findViewById (id );
46+ // 6,控件赋值。
4147 declaredField .set (activity , viewById );
4248 }
4349 }
You can’t perform that action at this time.
0 commit comments