1.sequence?first 返回sequence的第一个值。
2.sequence?last 返回sequence的最后一个值。
3.sequence?reverse 将sequence的现有顺序反转,即倒序排序
4.sequence?size 返回sequence的大小
5.sequence?sort 将sequence中的对象转化为字符串后顺序排序
6.sequence?sort_by(value) 按sequence中对象的属性value进行排序
二、Hash的内置函数
1.hash?keys 返回hash里的所有key,返回结果为sequence
2.hash?values 返回hash里的所有value,返回结果为sequence
例如:
<#assign user={“name”:“hailang”, “sex”:“man”}>
<#assign keys=user?keys>
<#list keys as key>
${key}=${user[key]}
</#list>
三、 操作字符串函数
1.substring(start,end)从一个字符串中截取子串
start:截取子串开始的索引,start必须大于等于0,小于等于end
end: 截取子串的长度,end必须大于等于0,小于等于字符串长度,如果省略该参数,默认为字符串长度。
例子:
${‘str’?substring(0)}à结果为str
${‘str’?substring(1)}à结果为tr
${‘str’?substring(2)}à结果为r
${‘str’?substring(3)}à结果为
${‘str’?substring(0,0)}à结果为
${‘str’?substring(0,1)}à结果为s
${‘str’?substring(0,2)}à结果为st
${‘str’?substring(0,3)}à结果为str
2.cap_first 将字符串中的第一个单词的首字母变为大写。
${‘str’?cap_first}à结果为Str
3. uncap_first将字符串中的第一个单词的首字母变为小写。
${‘Str’?cap_first}à结果为str
4.capitalize将字符串中的所有单词的首字母变为大写
${‘str’? capitalize}à结果为STR
5.date,time,datetime将字符串转换为日期
例如:
<#assign date1=”2009-10-12”?date(“yyyy-MM-dd”)>
<#assign date2=”9:28:20”?time(“HH:mm:ss”)>
<#assign date3=” 2009-10-12 9:28:20”?time(“HH:mm:ss”)>
${date1}à结果为2009-10-12
${date2}à结果为9:28:20
${date3}à结果为2009-10-12 9:28:20
注意:如果指定的字符串格式不正确将引发错误。
6.ends_with 判断某个字符串是否由某个子串结尾,返回布尔值。
${“string”?ends_with(“ing”)?string} 返回结果为true
注意:布尔值必须转换为字符串才能输出
7.html 用于将字符串中的<、>、&和“替换为对应得<>":&
8. index_of(substring,start)在字符串中查找某个子串,返回找到子串的第一个字符的索引,如果没有找到子串,则返回-1。
Start参数用于指定从字符串的那个索引处开始搜索,start为数字值。
如果start大于字符串长度,则start取值等于字符串长度,如果start小于0, 则start取值为0。
${“string”?index_of(“in”) à结果为3
${“string”?index_of(“ab”) à结果为-1
9.length返回字符串的长度 ${“string”?length}à结果为6
10.lower_case将字符串转为小写
${“STRING”?lower_case}à结果为string
11.upper_case将字符串转为大写
${“string”?upper_case}à结果为STRING
12.contains 判断字符中是否包含某个子串。返回布尔值
${“string”?contains(“ing”)?string} à结果为true
注意:布尔值必须转换为字符串才能输出
13.number将字符串转换为数字
${“111.11”?number}à结果为111.11
14.replace用于将字符串中的一部分从左到右替换为另外的字符串。
${“strabg”?replace(“ab”,”in”)} à结果为string
15. split使用指定的分隔符将一个字符串拆分为一组字符串
<#list “This|is|split”?split(“|”) as s>
${s}
</#list>
结果为:
This
is
split
16.trim 删除字符串首尾空格 ${“ String ”?trim} à结果为String
" "?trim 和 null?trim 都会返回空!
四、 操作数字
1. c 用于将数字转换为字符串
${123?c} à结果为123
2.string用于将数字转换为字符串
Freemarker中预订义了三种数字格式:number,currency(货币)和percent(百分比)其中number为默认的数字格式转换
例如:
<#assign tempNum=20>
${tempNum}
${tempNum?string.number}或${tempNum?string(“number”)} à结果为20
${tempNum?string.currency}或${tempNum?string(“currency”)} à结果为¥20.00
${tempNum?string. percent}或${tempNum?string(“percent”)} à结果为2,000%
五、操作布尔值
string 用于将布尔值转换为字符串输出
true转为“true”,false转换为“false”
foo?string(“yes”,”no”)如果布尔值是true,那么返回“yes”,否则返回no
六、判断是否为空
<#if (test)!> 可以判断是否为空,当传来的值为布尔型时,判断不为空后,仍会解析传来的值!
传来的值为""会认为是null,验证不通过。
<#if (test)??> 不管传来的值什么是什么类型,只会判断是否为空。
传来的值为""不会认为是null,验证通过。
freemarker
指令:<#xxx>
自定义指令<@xxx>
转换${1.1?int}
${aa?c}作用把String转换为数字,因为freemarker默认的会采用科学计数法,比如1,000,000
html:对字符串进行HTML编码
cap_first:使字符串第一个字母大写
lower_case:将字符串转换成小写
upper_case:将字符串转换成大写
trim:去掉字符串前后的空白字符
序列使用的:
size:获得序列中元素的数目
数字使用的:
int:取得数字的整数部分(如-1.9?int的结果是-1)
<#setting number_format="number"/>
<#setting date_format=""/>
<#setting time_format=""/>
<#setting datetime_format=""/>
<#assign answer=42/>
<#if s?exists>
${s?if_exists}
exists用在逻辑判断,而if_exists用来打印东西时用到,如果存在打印,不存在打印空字符串.
exp1?exists将会被exp1??代替
exp1?if_exists将会被exp1!代替
exp1?default(exp2)将会被exp1!exp2,这些在2.4版本中会体现到??
<#setting datetime_format="yyyy-MM-dd HH:mm"/>
<#setting date_format="yyyy-MM-dd"/>
<#setting time_format="HH:mm"/>
<#assign xxx="2006-10-13 10:30:20"/>
${xxx?datetime}
<#assign i=30/>
<#assign ii=30.00/>
<#assign str="test"/>
${ii},${ii?int},${ii?double},${ii?float},${i},${i?double},${str?if_exists},${s?if_exists},
<#if s?exists>
${"test"}
<#else>
${"noexists"}
<#assign x=1,y=2,z=3/>
<#if x=1>
x=1
<#elseif y=1>
y=1
<#elseif z=1>
z=1
<#list 1..6 as t>
xxx${t}
Crowdroid是由CrowdSourcing(众包)和Android各取其前、后部分组成而成的创新词汇,意在于通过使用Android终端设备,实现企业、机构(包括政府机关、学校、医院等单位)的CrowdSourcing(众包)服务。本软件本身是一个多服务微博客户端,包含了 twitter、新浪微博、腾讯微博、搜狐微博、Crowdroid for Business等服务,并具备推送信息的翻译、背景图片和字体的更换、图片的上传等功能。
现在Crowdroid 3.0.0最新版本已经发布啦:
★ 大幅改善了UI界面、用户体验
★ 新增转发微博页面并添加插入话题功能
★ 新增腾讯和搜狐修改个人资料的功能
★ 新增查看私信功能
★ 新增官方微博,以及反馈功能,方便用户反馈信息*
★ 修改添加多账户时,清除缓存信息
★ 新增更多种颜色选择,用于设置背景色及字体颜色
现将APK提供给各位下载使用哦:
普通版:http://www.anhuioss.com/download/android/crowdroid/Crowdroid3.0.0.apk
在程序代码中设定控件调用的方法
一般情况下,我们都是通过在XIB界面中添加控件,然后在程序中编写控件方法,最后通过XIB将控件和方法进行绑定。
本文,将介绍如何直接在程序中将编写的方法与控件进行绑定。
这里的例子将继续文章《通过Window-based Application创建项目(一) 》中的示例!
操作很简单,参考下面代码中的红色部分。
FirstViewController.h 修改:
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {
UILabel *label;
UIButton *button;
}
@property (nonatomic,retain) UILabel *label;
@property (nonatomic,retain) UIButton *button;
-(IBAction)myButtonClicked:(id)sender;
@end
FirstViewController.m 修改:
#import "FirstViewController.h"
@implementation FirstViewController
@synthesize label,button;
-(IBAction)myButtonClicked:(id)sender{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"my alert"
message:@"button is clicked"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[alert show];
[alert release];
}
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
//create the label
CGRect frame=CGRectMake(50, 30, 200, 45);
label=[[UILabel alloc] initWithFrame:frame];
label.text=@"This is a label";
//create the button
frame=CGRectMake(50, 100, 200, 45);
button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=frame;
[button setTitle:@"OK" forState:UIControlStateNormal];
[button addTarget:self
action:@selector(myButtonClicked:)
forControlEvents:UIControlEventTouchUpInside];
//add the label and button into current view.
[self.view addSubview:label];
[self.view addSubview:button];
[super viewDidLoad];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[label release];
[button release];
[super dealloc];
}
@end
运行后,点击界面上的【OK】按钮,即显示效果如下图:
关于控件对应方法在系统中的常量定义如下表:
Control Events
Kinds of events possible for control objects.
enum { UIControlEventTouchDown = 1 << 0, UIControlEventTouchDownRepeat = 1 << 1, UIControlEventTouchDragInside = 1 << 2, UIControlEventTouchDragOutside = 1 << 3, UIControlEventTouchDragEnter = 1 << 4, UIControlEventTouchDragExit = 1 << 5, UIControlEventTouchUpInside = 1 << 6, UIControlEventTouchUpOutside = 1 << 7, UIControlEventTouchCancel = 1 << 8, UIControlEventValueChanged = 1 << 12, UIControlEventEditingDidBegin = 1 << 16, UIControlEventEditingChanged = 1 << 17, UIControlEventEditingDidEnd = 1 << 18, UIControlEventEditingDidEndOnExit = 1 << 19, UIControlEventAllTouchEvents = 0x00000FFF, UIControlEventAllEditingEvents = 0x000F0000, UIControlEventApplicationReserved = 0x0F000000, UIControlEventSystemReserved = 0xF0000000, UIControlEventAllEvents = 0xFFFFFFFF };Constants UIControlEventTouchDown
A touch-down event in the control.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventTouchDownRepeatA repeated touch-down event in the control; for this event the value of the UITouchtapCount method is greater than one.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventTouchDragInsideAn event where a finger is dragged inside the bounds of the control.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventTouchDragOutsideAn event where a finger is dragged just outside the bounds of the control.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventTouchDragEnterAn event where a finger is dragged into the bounds of the control.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventTouchDragExitAn event where a finger is dragged from within a control to outside its bounds.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventTouchUpInsideA touch-up event in the control where the finger is inside the bounds of the control.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventTouchUpOutsideA touch-up event in the control where the finger is outside the bounds of the control.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventTouchCancelA system event canceling the current touches for the control.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventValueChangedA touch dragging or otherwise manipulating a control, causing it to emit a series of different values.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventEditingDidBeginA touch initiating an editing session in a UITextField object by entering its bounds.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventEditingChangedA touch making an editing change in a UITextField objet.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventEditingDidEndA touch ending an editing session in a UITextField object by leaving its bounds.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventEditingDidEndOnExitA touch ending an editing session in a UITextField object.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventAllTouchEventsAll touch events.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventAllEditingEventsAll editing touches for UITextField objects.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventApplicationReservedA range of control-event values available for application use.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventSystemReservedA range of control-event values reserved for internal framework use.
Available in iOS 2.0 and later.
Declared in UIControl.h.
UIControlEventAllEventsAll events, including system events.
Available in iOS 2.0 and later.
Declared in UIControl.h.