判断输入的文字是否为空

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();
   }
}

发布了56 篇原创文章 · 获赞 12 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/huwan12345/article/details/69226923