判断输入的文字是否为空

来源:互联网 发布:网络数据拦截分析工具 编辑:程序博客网 时间:2024/04/30 03:49

1、

仅仅是举例

//验证用户信息private void commitInfo() {    if (Util.isEmpty(userName.getText().toString())) {        CLToastUtil.showToast(ServiceRegistration.this, "您还没有输入姓名");    } else if (Util.isEmpty(companyName.getText().toString())) {        CLToastUtil.showToast(ServiceRegistration.this, "您还没有输入公司名称");    } else if (Util.isEmpty(companyAddress.getText().toString())) {        CLToastUtil.showToast(ServiceRegistration.this, "您还没有输入公司地址");    } else if (Util.isEmpty(qualitylabel.getText().toString())) {        CLToastUtil.showToast(ServiceRegistration.this, "您还没有输入公司性质标签");    } else if (Util.isEmpty(productServer.getText().toString())) {        CLToastUtil.showToast(ServiceRegistration.this, "您还没有输入公司产品服务");    } else if (Util.isEmpty(companyProfile.getText().toString())) {        CLToastUtil.showToast(ServiceRegistration.this, "您还没有输入公司简介");    } else {         //    }}
2、

对字符串的判断

public static boolean isEmpty(String s) {   if (null == s)      return true;   if (s.length() == 0)      return true;   if (s.trim().length() == 0)      return true;   if(s.equals("0"))      return true;   return false;}
3、

对Toast的封装

public class CLToastUtil {   private static Toast toast;    public static void showToast(Context context,String text){      if(toast == null){         toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);      }      toast.setText(text);      toast.show();    }   public static void showToast1(Context context,String text){      if(toast == null){         toast = Toast.makeText(context, text, Toast.LENGTH_LONG);      }      toast.setText(text);      toast.show();   }}

0 0
原创粉丝点击