Android Annotations
Originally I wanted to write a Java version of the "RESTful client library: restclient" for Android application development, the results found not very good to write, although the use of Dynamic Proxy to achieve most functions, but because the parameter name can not be obtained through reflection, and Java has no ducktype, plus there is no convenient type of Dict, make things difficult to see, bad use.
Later made the Fox recommended to me this Android Annotations, the method of annotation implementation is really good, so want to try, just in the EoE forum to see someone ask this thing have a can run example program reference, I went to try the official example, Can still be used, it is estimated that his configuration is wrong.
The configuration of this goods do have some trouble, I also follow the official website step by step to do to succeed, but the actual use do not know how, or write a Demo try it.
Configuration
The basic configuration method is from the official documentation (ECLIPSE).
First download the compiled package from here--of course, you can compile it yourself from the clone source on Github.
After unpacking you can get two jar files, one is Androidannotations-xxx.jar and the other is Androidannotations-api-xxx.jar.
Put the Aa-api-xxx.jar into the Libs directory, but Aa-xxx.jar can not be placed in the Libs directory, you can build another directory, for example, called Compile-libs.
Then open Project | Properties ...
To view the Java Compiler, determine that the Compiler compliance level must be 1.6.
View Java Compiler | Annontation processing, select Enabled annontation processing (You may need to select Enable project specific settings first).
View Java Compiler | Annontation Process | Factory Path, click Add JARs (You may need to select Enable Project specific settings) to add the Aa-xxx.jar that you just added.
Clicking OK will bring up a dialog that prompts annotation to set up changes and requires rebuild project to make sure that the project is rebuilt.
Finally, in the Java Build Path, select Libraries page, add JARs, add the Aa-api-xxx.jar just in.
Finally, modify the activity name in Androidmanifest and add "_" after it.
Configuration is complete.
Use
Take an example of an automatically generated blank item.
The first step is to modify the Manifest will default to XXX. Mainactivity name changed to. Mainactivity_. This underlined version is generated by Androidannotations.
Then go to modify the class Mainactivity code, the inside of the onCreate what all deleted, as long as this can automatically add OnCreate in the generated mainactivity_ and Setcontentview:
[Java]View Plaincopy
- @EActivity (R.layout.activity_main)
- public class Mainactivity extends Activity {
- }
If you need to use UI controls in your program, you do not need to write a whole bunch of findviewbyid and the corresponding coercion type conversions. This is all you need:
[Java]View Plaincopy
- @ViewById (R.id.hello)
- TextView Tvhello;
The basic usage is so simple.
For more usage see Cookbook and all available annotations instructions.
Of course, in the end, pour a basin of cold water. This thing is incompatible with a lot of unofficial libraries, and even I tried the official latest launch of the Support-actionbarcompat did not succeed.
Android Annotations Eclipse Configuration (3)