Want create site? Find Free WordPress Themes and plugins.

Butterknife is a light weight library to inject views into Android components. It uses annotation processing.

1. Butterknife

The @BindView annotation allow to inject views and performs the cast to the correct type for you. The @@OnClick(R.id.yourid) annotation allows to add OnClickListener to a view. You can optional define the method parameter of the view in case you want it injected.


Butterknife includes also findById methods which simplify code that still has to find views on a View, Activity, or Dialog. It uses generics to infer the return type and automatically performs the cast.


2. How does Butterknife work

Butterknife uses annotation processing to generated modified Java classes based on your annotations. Annotation processing is a tool build in javac for scanning and processing annotations at compile time.
You can define custom annotations and a custom processor to handle them. These annotations are scanned and processed at compile time. The annotation processor does not change the exiting input class but it generates a new Java class. This generated Java code is compiled again as a regular Java class.
The Butterknife annotation processor scans all Java classes looking for the Butterknife annotations. If a class contains these annotations, it generates a new class based on the <original_class>__ViewBinding schema.


Official Link



Other example which provide Butterknife:





2.  RemoveButterKnife plugin


ButterKnife is a wellknow open source tool to help you inject your view, but some times, you use plugin to gen butterknife’s code, but you don’t want to use it again.
It’s a very horrible job to delete every line inject code and write findviewbyid code, so, you can refer below plugin.




This lib is quite simple for removing Butterknife if user face any problem.


Writtern by : Bilal Ansari

Did you find apk for android? You can find new Free Android Games and apps.
No Comments

Post a Comment