Definitely not to be missed, butterknife use details

Source: Internet
Author: User

This blog original address: http://www.jianshu.com/p/b6fe647e368b

(1) What is Butterknife?

In the development process, we always write a lot of Findviewbyid and click events, such as the initial view, set view monitoring such as simple and repetitive operation makes people feel particularly troublesome, of course, not lazy programmers are not good programmers, naturally there is a corresponding solution-dependency injection. And Butterknife is to rely on the injection of relatively easy to understand the very good open-source framework, (in fact, Butterknife is not a strict sense of dependency injection, the following article will do analysis). But Butterknife as an annotated framework written by Jakewharton is widely used in Android development, and naturally has its own extraordinary. The following is a description of its use process.

(2) What are the advantages of butterknife?

For specific use of butterknife, please refer to the article
http://blog.csdn.net/itjianghuxiaoxiong/article/details/50177549
It's specific advantages:
1. Powerful View binding and click event handling to simplify code and improve development efficiency
2. Easy handling of Viewholder binding issues in Adapter
3. Runtime does not affect app efficiency, easy to use configuration
4. The code is clear, readability is strong

(3) What is the difference between butterknife and other dependency injection frameworks?

3.1 Dependency Injection framework differences in relation:
In fact, the main use of Android in the dependency injection framework for dagger, Butter Knife, Roboguice, Android Annotations. Here is a link:
Android ' s Options for Dependency Injection:dagger, Roboguice, and Butterknife
Corresponding translation articles: Android Dependency Injection: Dagger, Roboguice, and Butterknife.
3.2 Of course, this typical problem of course, stackoverflow up to see,

Approximate meaning:
The Buffer knife is injected into the view so that it can be injected into the non-activity and injected into the inflate views dagger can be injected into any object you want, as long as it is in the module class. Or it is a constructor. However, there is a lack of injection support for methods and fields. Buffer knife just avoids boilerplate code, Findviewbyid, that's all, so it can't be considered a real injection. It's just a view endorsement.

(4) What points of attention are there in the use of Butterknife?

Note:
1. Activity Butterknife.bind (this), must be in Setcontentview (); After, and after the parent class bind, the subclass does not need to bind
2. Fragment Butterknife.bind (this, mrootview);
3. Property layout cannot be decorated with private or static, otherwise it will be an error
4. Setcontentview () cannot be implemented by annotations.
5. Butterknife has been updated to version 7.0.1, the previous version is called the @InjectView , but now instead of called @Bind, more fit semantics.
6. During the fragment life cycle, Ondestoryview also needs butterknife.unbind (this)
7. Butterknife can no longer be used in your library module Oh!! This is because the ID value of the R field in your library is not final type, but your own application module is the final type. In response to this question, someone issue on Jack's GitHub, and he himself answered, click here.

(5) What if I want to be more lazy?

Haha, here is to add plug-ins, so that you write code faster.
The use of Zelezny plugins can make you more lazy (and code faster)

5.1 How to use plugins?

(6) Recommended Links:

1 butterknife GitHub address
2 Detailed Dagger2
3 android ' s Options for Dependency Injection:dagger, Roboguice, and Butterknife (here is the translation article link Android Dependency injection: Dagger, Roboguice and Butterknife)
4 Dagger official website
5 Questions about the application of Butterknife in the library
6 [8 best Android Studio plugins] (http://www.codeceo.com/article/8-android-studio-plugins.html)

Definitely not to be missed, butterknife use details

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.