标签:android java 使用 ar 代码 c har text
我们经常看到这样的代码:
public void setText(String text , TextView view , int string){
if(text == null || text.length() == 0){
// do something
}
}
其实在android里 if(text ==null || text.length()==0)是有封装的。
在android.text.TextUtils里
public static boolean isEmpty(CharSequence str) {
if (str == null || str.length() == 0)
return true;
else
return false;
}
所以我们可以使用
TextUtils.isEmpty(text)
代替
if(text == null || text.length() == 0)
CharSequence 是一个接口,String 实现了这个接口
使用TextUtils.isEmpty简单化代码,布布扣,bubuko.com
标签:android java 使用 ar 代码 c har text
原文地址:http://www.cnblogs.com/Hellcxs/p/3891388.html