<span id="Label3"></p><p><p><span style="font-size:14px">The purpose of writing the program is of course to provide users with products and services, writing procedures are hard, sometimes to work overtime, to catch broken scalp and so On. In the process of writing a program, we should try to make the development work easier and more interesting. Every thing we can do is to minimize the amount of code and not to reinvent the wheel. The purpose of Android open source framework Androidannotations (i'm referred to as the AA Framework) is that, of course, the amount of code is reduced, not just to make work easier, to make it easier for people to read code, and to maintain Code. In the project being developed, we use the androidannotations annotation framework, so simply say:</span></p></p><p><p><span style="font-size:14px">Androidannotations's official website: http://androidannotations.org/and GitHub website: https://github.com/excilys/androidannotations/ wiki, Two Web site details of the advantages and use of the framework, the framework of the construction work can be referred to: http://blog.csdn.net/limb99/article/details/9067827. Here's A comparison of the code with two simple activity (using the same layout file, a simple 6-control):</span></p></p><p><p><span style="font-size:14px">-------------the notation of a non-annotated frame-----------------</span></p></p><p><span style="font-size:14px">public class Testactivity extends Activity {<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Private TextView textView01;<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Private TextView textView02;<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Private TextView textView03;<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Private TextView textView04;<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Private TextView textView05;<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Private button button;<br><br><br><span style="white-space:pre"><span style="white-space:pre"></span></span>@Override<br><span style="white-space:pre"><span style="white-space:pre"></span></span>protected void OnCreate (Bundle Savedinstancestate) {<br><span style="white-space:pre"><span style="white-space:pre"></span></span>TODO auto-generated Method Stub<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Super.oncreate (savedinstancestate);<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Setcontentview (r.layout.activity_main);<br><span style="white-space:pre"><span style="white-space:pre"></span></span>this.textview01 = (TextView) Findviewbyid (r.id.textview01);<br><span style="white-space:pre"><span style="white-space:pre"></span></span>this.textview02 = (TextView) Findviewbyid (r.id.textview02);<br><span style="white-space:pre"><span style="white-space:pre"></span></span>this.textview03 = (TextView) Findviewbyid (r.id.textview03);<br><span style="white-space:pre"><span style="white-space:pre"></span></span>this.textview04 = (TextView) Findviewbyid (r.id.textview04);<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textview05 = (TextView) Findviewbyid (r.id.textview05);<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.button = (button) Findviewbyid (r.id.button);<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.button.setOnClickListener (new Onclicklistener () {<br><br><br><span style="white-space:pre"><span style="white-space:pre"></span></span>@Override<br><span style="white-space:pre"><span style="white-space:pre"></span></span>public void OnClick (View V) {<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Implement Click events<br><span style="white-space:pre"><span style="white-space:pre"></span></span>}<br><span style="white-space:pre"><span style="white-space:pre"></span></span>});<br><span style="white-space:pre"><span style="white-space:pre"></span></span>}<br><span style="white-space:pre"><span style="white-space:pre"></span></span>@Override<br><span style="white-space:pre"><span style="white-space:pre"></span></span>protected void Onresume () {<br><span style="white-space:pre"><span style="white-space:pre"></span></span>TODO auto-generated Method Stub<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Super.onresume ();<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Setviewdata ();<br><span style="white-space:pre"><span style="white-space:pre"></span></span>}<br><span style="white-space:pre"><span style="white-space:pre"></span></span>private void Setviewdata () {<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView01.setText ("no AA Frame Test 1");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView02.setText ("no AA Frame Test 2");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView03.setText ("no AA Frame Test 3");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView04.setText ("no AA Frame Test 4");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView05.setText ("no AA Frame Test 5");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>}<br>}</span></p><p><p><span style="font-size:14px">---------used the androidannotations annotation framework----------------------</span></p></p><p><p><span style="font-size:14px">@EActivity (r.layout.activity_main)<br>public class Aatestactivity extends Activity {<br><span style="white-space:pre"></span>@ViewById (r.id.textview01)<br><span style="white-space:pre"></span>TextView textView01;<br><span style="white-space:pre"></span>@ViewById (r.id.textview02)<br><span style="white-space:pre"></span>TextView textView02;<br><span style="white-space:pre"></span>@ViewById (r.id.textview03)</span></p></p><p><span style="font-size:14px"><span style="white-space:pre"><span style="white-space:pre"></span></span>TextView textView03;<br><span style="white-space:pre"><span style="white-space:pre"></span></span>@ViewById (r.id.textview04)<br><span style="white-space:pre"><span style="white-space:pre"></span></span>TextView textView04;<br><span style="white-space:pre"><span style="white-space:pre"></span></span>@ViewById (r.id.textview05)<br><span style="white-space:pre"><span style="white-space:pre"></span></span>TextView textView05;<br><span style="white-space:pre"><span style="white-space:pre"></span></span>@ViewById (r.id.button)<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Button button;<br><br><br><span style="white-space:pre"><span style="white-space:pre"></span></span>@Click (r.id.button)<br><span style="white-space:pre"><span style="white-space:pre"></span></span>void Btnclick () {<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Implement Click events<br><span style="white-space:pre"><span style="white-space:pre"></span></span>}<br><br><br><span style="white-space:pre"><span style="white-space:pre"></span></span>@Override<br><span style="white-space:pre"><span style="white-space:pre"></span></span>protected void Onresume () {<br><span style="white-space:pre"><span style="white-space:pre"></span></span>TODO auto-generated Method Stub<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Super.onresume ();<br><span style="white-space:pre"><span style="white-space:pre"></span></span>Setviewdata ();<br><span style="white-space:pre"><span style="white-space:pre"></span></span>}<br><br><br><span style="white-space:pre"><span style="white-space:pre"></span></span>private void Setviewdata () {<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView01.setText ("no AA Frame Test 1");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView02.setText ("no AA Frame Test 2");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView03.setText ("no AA Frame Test 3");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView04.setText ("no AA Frame Test 4");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>This.textView05.setText ("no AA Frame Test 5");<br><span style="white-space:pre"><span style="white-space:pre"></span></span>}<br>}<br></span></p><p><p><span style="font-size:14px">In contrast, with the notation, you do not have to repeat the Findviewbyid () and write onclick () events. These two classes of code to see the difference is not obvious, the main control less, and the implementation of less functionality, when our layout page is very complex, to achieve a lot of listening, the advantages of using the annotation method is Obvious. There are many annotation methods, can refer to the http://doc.okbase.net/rain_butterfly/archive/95335.html, the use is very convenient, and after simple testing, the annotation framework has a very small impact on the performance of the Program.</span></p></p><p><p><span style="font-size:14px">But when it comes to use, individuals find a couple of places that don't feel good:</span></p></p><p><p><span style="font-size:14px">1, the control we write in the activity, such as a button, cannot be written as a privately owned private Button Btn.</span></p></p><p><p><span style="font-size:14px">2, In addition to the Androidmanifest.xml list file to the corresponding acitivity (such as Aatestactivity) written aatestactivity _ can Be.</span></p></p><p><p><span style="font-size:14px">3, the debug program may be Inconvenient.</span></p></p><p><p>Android Annotation Framework Androidannotations Introduction</p></p></span>
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