Android Annotations 介绍
来源:互联网 发布:淘宝金冠 编辑:程序博客网 时间:2024/05/18 16:58
开发过程中看到别人使用了Android Annotations的代码,该代码是一个第三方框架,通过注释来开发应用。使用Android Annotations能够大大减少代码量。
请看下面的Java代码
package com.example.androidannotations; import android.app.Activity; import android.widget.TextView; import com.googlecode.androidannotations.annotations.AfterViews; import com.googlecode.androidannotations.annotations.EActivity; import com.googlecode.androidannotations.annotations.ViewById; //Eactivity注释可以设置Layout,相当于setConentView方法 @EActivity(R.layout.activity_main) public class MainActivity extends Activity { //ViewById注释功能与findViewById相同,如果声明的变量名就是id,可以省去参数,否则应加上id,如ViewById(R.id.tv) @ViewById TextView tv; //AfterViews注释定义的方法会在OnCreate方法的setContentView后执行 @AfterViews void init() { tv.setText("asfsdf"); } } package com.example.androidannotations; import android.app.Activity; import android.widget.TextView; import com.googlecode.androidannotations.annotations.AfterViews; import com.googlecode.androidannotations.annotations.EActivity; import com.googlecode.androidannotations.annotations.ViewById; //Eactivity注释可以设置Layout,相当于setConentView方法 @EActivity(R.layout.activity_main) public class MainActivity extends Activity { //ViewById注释功能与findViewById相同,如果声明的变量名就是id,可以省去参数,否则应加上id,如ViewById(R.id.tv) @ViewById TextView tv; //AfterViews注释定义的方法会在OnCreate方法的setContentView后执行 @AfterViews void init() { tv.setText("asfsdf"); } }
一些常用注释的使用方法:
@AfterInject 定义的方法在类的构造方法执行后执行
@AfterTextChange定义的方法在TextView及其子类的Text属性改变后执行
@AfterViews 定义的方法在setContentView后执行
@Background 定义的方法在后台线程执行
@BeforeTextChange 定义的方法在TextView及其子类的Text属性改变前执行
@Click 定义点击监听器
@EActivity 在Activity中启用Annotations
@EProvider 在 ContentProvider中启用Annotations
@EReceive 在BroadcastReceiver中启用Annotations
@EService 在Service中启用Annotations
@EView 在自定义的View的子类中启用Annotations
@Fullscreen 全屏
@NoTitle 无标题栏
掌握这些注视对读懂利用该第三方代码开发的代码非常有帮助,同时对利用该代码开发的APK文件反编译的解释能够有更深入的了解。
3 0
- Android Annotations 介绍
- Android Annotations 介绍
- Android Annotations 介绍
- Android Annotations
- Android Annotations
- Android annotations
- android annotations
- struts-annotations-plugin 介绍
- tapestry注释介绍Annotations
- tapestry注释介绍Annotations
- tapestry注释介绍Annotations
- 试用Android Annotations
- Android Annotations浅析
- Android Annotations浅析
- android工具-annotations
- android工具-annotations
- 简单试用Android Annotations
- Android Annotations浅析
- C/C++日常学习总结(第一篇)const用法及printf的执行顺序
- Android开发文档——Notifications
- thinkphp多表查询及分页实现
- 【linux设备模型】之platform设备驱动
- Spring MVC拦截器,登录拦截简单配置
- Android Annotations 介绍
- Linux服务器集群系统——LVS集群的体系结构
- UVa 10970 - Big Chocolate
- hdfs安全模式导致hbase执行失败,提示zookeeper相关错误
- 导出CCS3.3数据及使用matlab处理的方法
- 网信金融战略入股打车应用Hailo
- 超级硬盘数据恢复软件 4.5.5.3注册码破解版
- 站长应该如何对待百度经常的算法调整
- How to remove a line from a file in java?