Andorid之Annotation框架初使用(四)
代替繁琐的finViewById
@EActivity
public class MyActivity extends Activity {
// Injects R.id.myEditText
@ViewById
EditText myEditText;
@ViewById(R.id.myTextView)
TextView textView;
}
指定需要在视图加载完成后才能执行的方法@AfterViews
@EActivity(R.layout.main)
public class MyActivity extends Activity {
@ViewById
TextView myTextView;
@AfterViews
void updateTextWithDate() {
myTextView.setText("Date: " + new Date());
}
}
注意:不要在onCreate中写任何对view相关的方法
@Extra 用于传递的Intent
@EActivity
public class MyActivity extends Activity {
@Extra("myStringExtra")
String myMessage;
@Extra("myDateExtra")
Date myDateExtraWithDefaultValue = new Date();
// The name of the extra will be "myMessage"
@Extra
String myMessage;
}
onNewIntent能够根据Intent重新注入Extra
@EActivity
public class MyActivity extends Activity {
@Extra("myStringExtra")
String myMessage;
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
}
}
@SystemService
no more Context.getSystemService()
@EActivity
public class MyActivity extends Activity {
@SystemService
NotificationManager notificationManager;
}
@SharedPref:
定义:
@SharedPref
public interface MyPrefs {
// The field name will have default value "John"
@DefaultString("John")
String name();
// The field age will have default value 42
@DefaultInt(42)
int age();
// The field lastUpdated will have default value 0
long lastUpdated();
@DefaultRes(R.string.defaultPrefName)
String resourceName(); @DefaultRes
String defaultPrefAge();
}
使用:
@EActivity
public class MyActivity extends Activity {
@Pref
MyPrefs_ myPrefs;
} // Simple edit
myPrefs.name().put("John"); // Batch edit
myPrefs.edit()
.name()
.put("John")
.age()
.put(42)
.apply(); // Preference clearing:
myPrefs.clear(); // Check if a value exists:
boolean nameExists = myPrefs.name().exists(); // Reading a value
long lastUpdated = myPrefs.lastUpdated().get(); // Reading a value and providing a fallback default value
long now = System.currentTimeMillis();
long lastUpdated = myPrefs.lastUpdated().getOr(now);
Andorid之Annotation框架初使用(四)的更多相关文章
- Andorid之Annotation框架初使用(六)
EVENT @Click :点击事件,只能有0个或1个参数,且参数为View @Click(R.id.myButton) void myButtonWasClicked() { [...] } @Cl ...
- Andorid之Annotation框架初使用(七)
Save Instance State:程序保留Activity的实例状态 , 在onSaveInstanceState(Bundle)被系统调用的时候自动保存 , onCreate(Bundle)被 ...
- Andorid之Annotation框架初使用(五)
注入res文件夹的资源: @StringRes @EActivity public class MyActivity extends Activity { @StringRes(R.string.he ...
- Andorid之Annotation框架初使用(三)
线程使用: @Background这个是使用了cached thread pool executor , 阻止开启过多的线程 可以为@Background指定一个id,用于随时终止线程的操作(Back ...
- Andorid之Annotation框架初使用(二)
Fragment: @EActivity(R.layout.fragments) public class MyFragmentActivity extends FragmentActivity { ...
- Andorid之Annotation框架初使用(一)
1. 设置Activity的布局 @EActivity(R.layout.main) public class MyActivity extends Activity {} 注: 此时在Android ...
- AVFoundation 框架初探究(二)
接着第一篇总结 系列第一篇地址:AVFoundation 框架初探究(一) 在第一篇的文章中,我们总结了主要有下面几个点的知识: 1.对AVFoundation框架整体的一个认识 2.AVSpeech ...
- Golang 网络爬虫框架gocolly/colly 四
Golang 网络爬虫框架gocolly/colly 四 爬虫靠演技,表演得越像浏览器,抓取数据越容易,这是我多年爬虫经验的感悟.回顾下个人的爬虫经历,共分三个阶段:第一阶段,09年左右开始接触爬虫, ...
- Spring框架的第四天(整合ssh框架)
## Spring框架的第四天 ## ---------- **课程回顾:Spring框架第三天** 1. AOP注解方式 * 编写切面类(包含通知和切入点) * 开启自动代理 2. JDBC模板技术 ...
随机推荐
- jmeter-----GUI运行和非GUI运行的区别
gui:界面会消耗很多资源,并且运行的结果是保存在Jmeter运行的内存中.当时间一长,内存增长到一定程度,就会报错,甚至假死. 非gui:实时的将运行log文件保存到本地文件中,不会撑爆内存.并且对 ...
- netty 基础知识
http://my.oschina.net/bieber/blog/406799 线程模型 http://hongweiyi.com/2014/01/netty-4-x-thread-model/ h ...
- ubuntu下 pycharm使用andcoda下的tensorflow
在ubuntu中 tensorflow是安装在andconda里的一个虚拟环境中,他就相当于一个容器,将tensorflow的整个环境去模拟隔离出来,因为我们直接使用andconda库去作为pycha ...
- 洛谷P3639 [APIO2013] 道路费用 [生成树的特殊算法]
题目传送门 道路费用 格式难调,题面就不放了. 分析: 这是一道要细(yan)心(jing)的生成树的好(gui)题. 首先我们看到$k$的范围非常小,那么我们就可以直接$2^k$枚举每一条加边是否选 ...
- Python数据类型-列表(list)增删改查
1.添加元素 添加单个元素:使用append(object)函数可以为列表添加单个元素,参数object为对象:也就是说所有Python的对象都可以添加到列表中. 添加多个元素(合并列表):使用ext ...
- 【拓扑排序或差分约束】Guess UVALive - 4255
题目链接:https://cn.vjudge.net/contest/209473#problem/B 题目大意:对于n个数字,给出sum[j]-sum[i](sum表示前缀和)的符号(正负零),求一 ...
- iOS 9音频应用播放音频之音量设置与声道设置
iOS 9音频应用播放音频之音量设置与声道设置 iOS 9音频应用音量设置 音量又称响度.音强,是指人耳对所听到的声音大小强弱的主观感受,其客观评价尺度是声音的振幅大小.在iOS 9音频应用的应用中, ...
- ESXI 5.5卡在LSI_MR3.V00
方法一 故障现象 此问题无论使用VMware官方镜像还是HP的自定义镜像都会出现一下情况并卡着不动.(此文档普遍存在各种服务器上,包括其它厂商服务器) 故障原因: 故障原因VMware官方和HP官方并 ...
- 2017四川省赛D题《Dynamic Graph》
题意:给出一个n个点m条边的有向无环图(DAG),初始的时候所有的点都为白色.然后有Q次操作,每次操作要把一个点的颜色改变,白色<->黑色,对于每次操作,输出满足下列点对<u,v&g ...
- FFTW3学习笔记1:VS2015下配置FFTW3(快速傅里叶变换)库
一.FFTW简介 FFTW ( the Faster Fourier Transform in the West) 是一个快速计算离散傅里叶变换的标准C语言程序集,其由MIT的M.Frigo 和S. ...