{"id":1275,"date":"2023-03-18T10:03:08","date_gmt":"2023-03-18T02:03:08","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1275"},"modified":"2023-04-29T09:22:57","modified_gmt":"2023-04-29T01:22:57","slug":"android-butterknefe-record","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/android-butterknefe-record\/","title":{"rendered":"Android Butterknife \u91c7\u5751\u8bb0\u5f55"},"content":{"rendered":"<h2>\u5b50module\u4e2d\u4f7f\u7528<\/h2>\n<p>\u5728Library module\u4e2d\u4f7f\u7528\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/JakeWharton\/butterknife#library-projects\">https:\/\/github.com\/JakeWharton\/butterknife#library-projects<\/a><\/p>\n<p>Now make sure you use R2 instead of R inside all Butter Knife annotations.<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">class ExampleActivity extends Activity {\n    @BindView(R2.id.user)\n    EditText username;\n    @BindView(R2.id.pass)\n    EditText password;\n\n    @OnClick({R2.id.btn_alipay, R2.id.btn_wechat})\n    void onClick(View view) {\n        int id = view.getId();\n        if (id == R.id.btn_alipay) {\n\n        } else if (id == R.id.btn_wechat) {\n\n        }\n    }\n}<\/code><\/pre>\n<h2>\u6210\u5458\u53d8\u91cf\u4e0d\u80fd\u4f7f\u7528private\u4fee\u9970<\/h2>\n<pre><code>@BindView fields must not be private or static.<\/code><\/pre>\n<p>\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/JakeWharton\/butterknife\/issues\/518\">https:\/\/github.com\/JakeWharton\/butterknife\/issues\/518<\/a><\/p>\n<ul>\n<li>\u9519\u8bef\u59ff\u52bf<\/li>\n<\/ul>\n<pre><code class=\"language-java\">@BindView(R2.id.btn_success)\nprivate Button btnSuccess;\n@BindView(R2.id.btn_failure)\nprivate Button btnFailure;<\/code><\/pre>\n<ul>\n<li>\u6b63\u786e\u59ff\u52bf<\/li>\n<\/ul>\n<pre><code class=\"language-java\">@BindView(R2.id.btn_success)\nButton btnSuccess;\n@BindView(R2.id.btn_failure)\nButton btnFailure;<\/code><\/pre>\n<h2>Fragment\u4e2d\u7ed1\u5b9a<\/h2>\n<pre><code class=\"language-java\">@Nullable\n@Override\npublic View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {\n    View view = inflater.inflate(R.layout.fragment_home, container, false);\n    ButterKnife.bind(this, view);\n    initView(view);\n    return view;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b50module\u4e2d\u4f7f\u7528 \u5728Library module\u4e2d\u4f7f\u7528\u53c2\u8003\uff1ahttps:\/\/github.com\/Jake [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[],"class_list":["post-1275","post","type-post","status-publish","format-standard","hentry","category-butterknife"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1275"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1275\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}