Use of annotated framework Butterknife for Android development

Source: Internet
Author: User

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

Related Article

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.