Android开发EditText的isNullOrEmpty判断有问题
Android开发EditText的isNullOrEmpty判断有问题
比如下面的代码,如果输入的空格,得到的结果是false。
etView.text.isNullOrEmpty()
按照我们的设想应该是true才对,是不是。
所以我们还得去掉空格才行。
/**
* 去除字符串中的空格、回车、换行符、制表符
*
* @param str
* @return
*/
public static String replaceBlank(String str) {
String dest = "";
if (str != null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}
修改后的代码如下:
TextUtils.isEmpty(Utils.replaceBlank(etSecretMessage.text.toString())