首页 > 代码库 > ButterKnife 原理

ButterKnife 原理

在含有ButterKnife工程中你会 ButterKnife会帮你生成一些类似$ViewBinder文件 文件用反编译工具打开你会看到如下代码:

public class ExampleActivity$$ViewBinder<T extends         io.bxbxbai.samples.ui.ExampleActivity> implements ViewBinder<T> {     @Override public void bind(final Finder finder, final T target, Object source) {          View view;          view = finder.findRequiredView(source, 21313618, “field ‘user’”);          target.username = finder.castView(view, 21313618, “field ‘user’”);          view = finder.findRequiredView(source, 21313618, “field ‘pass’”);          target.password = finder.castView(view, 21313618, “field ‘pass’”);          view = finder.findRequiredView(source, 21313618, “field ‘submit’ and method ‘submit’”);          view.setOnClickListener(            new butterknife.internal.DebouncingOnClickListener() {               @Override public void doClick(android.view.View p0) {      target.submit();           }        });      }
技术分享

ButterKnife 原理