Android Annotations 配置
来源:互联网 发布:知止可以不殆什么意思 编辑:程序博客网 时间:2024/05/17 21:49
做过JavaEE肯定对Spring不陌生,尤其是spring的IOC,真是太好用了。顺着这个思想,Android上有没有spring来实现IOC。搜索一下,果然spring已经推出了spring for android,不过可惜的是它并不支持IOC,但是却在官网发现了这个么一篇文章http://blog.springsource.org/2011/08/26/clean-code-with-android/,里面讲了android依赖注入(IOC)的实现思想和已经实现依赖注入的几个项目,自己感觉AndroidAnnotations最为出色,不仅jar包小,而且功能强大,极大的减少了代码量。本文将会讲到AndroidAnnotations的部署和简单应用。
配置:
1、下载并导入jar包,有两个jar包,分别是androidannotations-3.1.jar 和androidannotations-api-3.1.jar . 下载下来后将androidannotations-api-3.1.jar放置到你项目的libs目录下,并在项目中新建一个compile-libs的文件夹把androidannotations-3.1.jar放到该文件下,两个jar不可放在同一文件夹下。
2、配置Eclipse,
2.1、 Project-->JavaCompiler 设置"Compiler compliance level" 在1.6以上,否则不会运作
2.2、 Project-->JavaCompiler -> "Annotation Processing",勾选"Enable annotion processing" ( 并且在描述那一行写上“apt_generated” 因为会在你项目中的跟目录生成该文件夹,用来装XXActivity_的)
2..3 "Properties" -> "Java Compiler" -> "Annotation Processing" -> "Factory Path",勾选上“Enable project specific settings” 并添加androidannotations-x.x.x.jar(注意别添加错了哦,不是androidannotations-api-3.1.jar)
2.4 右键libs下的androidannotations-api-3.1.jar 选择“Builde Path”
好了,到现在为止你的项目就可以用annotations框架了,里面很多标签就可以直接拿来用了
除了@Eactivity @ViewById@Click之外还有
@EApplication
@EBean
@EFragment
@EService
@EView
@EviewGroup
@App
@Bean
@Fullscreen
但是要注意的是你要用到Annotations的Activity要在AndroidManifest.xml文件中加一个下划线。 例如
<span style="background-color: rgb(255, 255, 255);"> <activity android:name="com.example.yidiannews_.WelcomeActivity" android:label="@string/title_activity_welcome" > </activity></span>gai
<activity android:name="com.example.yidiannews_.WeatcherActivity_" android:label="@string/title_activity_weatcher" >
</activity>
这个时候你项目的跟目录下面就会多出一个apt_generated 文件夹,它装着XXActivity_的文件
下面是我自己配置的一个Activity的部分代码:
@EActivity(R.layout.activity_weatcher)public class WeatcherActivity extends BaseActivity implements ResponseData{ @ViewById(R.id.title) //标题 protected TextView mTitle; @ViewById(R.id.loacl) protected TextView mLocal; //地区 @ViewById(R.id.layout) protected RelativeLayout mLayout;//整个天气布局的layout
<span style="white-space:pre"></span>//选择城市添加侦听事件<span style="white-space:pre"></span>@Click(R.id.loacl)<span style="white-space:pre"></span> public void chooseCity(View view){<span style="white-space:pre"></span>Toast.makeText(this, "选择城市", Toast.LENGTH_LONG).show();<span style="white-space:pre"></span>}
- Android Annotations 配置
- Android Studio 配置Annotations
- Android Studio配置Annotations
- Android Studio 配置 android annotations
- Android Annotations配置与使用
- Android Studio1.5 配置Android annotations
- Android Studio中配置 Android annotations
- Android Studio 1.5+ 配置Android Annotations框架
- Android Annotations在Eclipse下配置
- Intellij IDEA配置Android Annotations注解框架
- Intellij IDEA配置Android Annotations注解框架
- Android Annotations 4.0.0 配置Rest API
- Android Annotations在studio上的配置
- Android Annotations
- Android Annotations
- Android annotations
- android annotations
- Android 最火快速开发框架Android Annotations配置详解
- 制作iOS Ad-Hoc测试应用流程
- 移动开发框架,第【二】弹:Hammer.js 移动设备触摸手势js库
- ORACLE的char、nchar、varchar、varchar2、nvarchar2的区别
- 老外谈设计:2015国外Web设计新思路分享
- UML 序列图(时序图)
- Android Annotations 配置
- XHR XMLHttpRequest() progress
- IOS单例模式及单例模式的优缺点
- 剑指offer 05: 从尾到头打印链表
- mfc 绘图中的坐标空间转换问题
- Hive 日期函数 weekofyear
- repeater动态添加行
- 利用1stOpt进行logistic函数非线性拟合
- 纯CSS实现表单验证