您的位置:首页 > 移动开发 > Android开发

android annotation配置及简单使用

2016-08-17 22:52 381 查看
1.环境配置

将 android annotations-api-3.1.jar拷贝到libs目录下

在项目的根目录中创建compile-libs 并放置 androidannotations-3.1.jar

2.右键单击项目->properties->



3.勾选Enable annotation processing

4.添加 jar文件



另外在一些Eclipse 中可能找不到Annotation Processing 这个选项。

这个需要安装一下插件。安装插件的步骤为:

1.单击Eclipse 中的Help->Install New Sorftware

Juno - http://download.eclipse.org/releases/juno



注意,标红的地方不要勾选,否则速度为很慢的。

整个项目的配置工作已经完成了,现在直接进入开发。

几个常用的标签

1.@EActivity

对布局文件进行注解,类似于setContentView(R.layout.activity_log);

2.@ViewById

@ViewById(R.id.user_password)

public EditText user_password;

可以在后面不跟着对应的Id,但是布局文件中的id必须和创建控件对应的名称必须一致。

@ViewById

public EditText user_name;

对多个控件进行@ViewById

@ViewById

TextView tv2,tv3;

3.@Click

设置单个Button的点击事件

@Click(R.id.login)

public void login(){

};

设置多个Button的点击事件。

4.@Background

在子线程中运行的方法,在方法上添加注解,方法会在子线程中运行。

public void dobackground(){

Log.i(TAG, “当前运行的线程”+Thread.currentThread().getId());

}

5.@UiThread

在UI线程中运行的方法

6.@StringRes

@StringRes

String str1;

7.@Extra

@Extra(“user_name”)

String name;

@AfterViews

初始化View之后执行的方法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android eclipse annotation