Use Butter Knife library to inject views in Android

    Code injection is usually something we try and avoid, but Jake Wharton is using injection for good. With his open source “Butter Knife” library, you can use annotations to conveniently create commonly used code for Views in Android. In this post, I present how to implement it in an Android Project.

1. Setup in project

- Download jar file at it's HOME PAGE.
- Add jar to your Android project(also java build) and configure appropriate annotation settings. See here for instructions for Eclipse and here for instruction for IntelliJ.

2. Implement

- Create an activity layout and a fragment layout simple like these:
- In programmatically code, we must:
+ Declaring "inject" views from xml.
+ Set events for them (simply is using them).

Full java code:
Okey, as you can see, codes is simple and after build and run program, we have this result:

pic name pic name pic name
Jake Wharton Pages:
- Github:
- Website:
(Sorry for having ads)


Previous post
« Prev Post
Next post
Next Post »