我们经常看到这样的代码:
其实在android里 if(text ==null || text.length()==0)是有封装的。
在android.text.TextUtils里
所以我们可以使用
代替
CharSequence 是一个接口,String 实现了这个接口
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 实现了这个接口