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模板技术 ...
随机推荐
- centos6下mysql的主从复制的配置
2015年9月17日 23:00:36 update 想要好好了解mysql复制,还是去看看<高性能MySQL>(第三版)好了,上面说的比较详细. =========== 在本地用virt ...
- 关于ZIP自动打包的进一步进化思路
http://blog.163.com/long200259@126/blog/static/11288755920093120529157/
- 洛谷 P2945 [USACO09MAR]沙堡Sand Castle 题解
题目传送门 大概思路就是把这两个数组排序.在扫描一次,判断大小,累加ans. #include<bits/stdc++.h> using namespace std; int x,y,z; ...
- iOS客户端学习之AES加密
数据加密在解密在软件开发过程中举足轻重的作用,可能有的公司在加密的时候有自己公司内部一套设计的算法,而在这方面不想浪费太大精力就可以去考虑使用第三方提供的加密算法,如AES加密算法,本篇内容介绍开源中 ...
- entityframework删除时提示“DELETE 语句与 REFERENCE 约束”的解决方法。
1.加入List对象的Include var entity = db.XinDes.Include("Reviews").First(); db.XinDes.Remove(ent ...
- day4装饰器
Python装饰器 1.必备 def foo(): print(foo) <function foo at 0x7f62db093f28> >>> foo <fun ...
- beautifulsoup简单用法
原文地址 http://www.cnblogs.com/yupeng/p/3362031.html 这篇文章讲的也很全 http://www.cnblogs.com/twinsclover/archi ...
- MFC+WinPcap编写一个嗅探器之零(目录)
零零散散写了三天,完成了编写嗅探器的文章,旨在让自己加深印象,是初学者少走一些弯路.因为先前未接触MFC,之后也不打算精通,完全是0基础,所以文章技术含量不高,但难点基本上都都包括了,凑合这看吧,接下 ...
- python动态获取对象的属性和方法 (转)
转自未知,纯个人笔记使用 首先通过一个例子来看一下本文中可能用到的对象和相关概念. #coding:utf-8 import sys def foo():pass class Cat(object): ...
- 20179202《Linux内核原理与分析》第一周作业
实验一 Linux 系统简介 这一节主要学习了Linux的历史,重要人物以及学习Linux的方法.Linux和Windows在是否收费.软件与支持.安全性.可定制性和应用范畴等方面都存在着区别.目前感 ...