Butterknife official website
In fact, butterknife annotation style, and xutils viewutils module basically almost, as long as the use of xutils, the framework will be basically.
First, the principle.
Recently found a very useful open source framework, pretty good, can simplify your code, is about annotations. Not much to say directly into the use of steps to explain.
Second, step.
1, the preparation stage, first to the official website (http://jakewharton.github.io/butterknife/) on the jar package, download down.
2, the download down the jar package, put in the project Libs, will automatically import the project.
3, the configuration eclips, the mouse alignment needs the annotation item, right click Poperties–>java compiler–>
Annotation procession–> hook to Enable project specific settings The others will automatically hook up.
–> Factory Path (Hook enable project specific settings) –> last add .... JARs the jar package that was just downloaded. This eclips configuration is possible.
4, the following is a picture explanation.
5, is to use annotations, directly on the code.
XML section
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent" >5 <TextView6 Android:id= "@+id/tv_test"7 Android:layout_width= "Wrap_content"8 Android:layout_height= "Wrap_content"9 Android:layout_centerhorizontal= "true"Ten android:layout_centervertical= "true" One Android:text= "@string/hello_world" A Tools:context=". Mainactivity " /> - </Relativelayout>
Java section
1 PackageCom.msquirrel.main;2 ImportButterknife. Butterknife;3 ImportButterknife. Injectview;4 ImportButterknife. OnClick;5 ImportAndroid.os.Bundle;6 Importandroid.app.Activity;7 ImportAndroid.widget.TextView;8 9 Ten Public classMainactivityextendsActivity { One A @InjectView (r.id.tv_test) - TextView tvtest; - the @Override - Public voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); +Butterknife.inject ( This); -Tvtest.settext ("Test"); + } A at @OnClick (r.id.tv_test) - Public voidSayhi () { -Tvtest.settext ("hello!"); - } -}
This will allow you to use annotations if you are finished.
Use of annotated framework Butterknife for Android development