本文介绍了检查空文本编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个简单的注册应用程序,用户需要填写一些字段,其中有些是强制性的。所以,我需要检查,如果用户写入的信息在那里。我这样做:

 为(RequireFields按r:RequireFields.values​​()){
        如果(boolValue()){
            开关(r.getField()){
                案名:
                    的System.out.println(姓名);
                    打破;
                案姓:
                    的System.out.println(姓);
                    打破;
                案通:
                    的System.out.println(通行证);
                    打破;
                案电子邮件:
                    的System.out.println(电子邮件);
                    打破;
                案街:
                    的System.out.println(街道);
                    打破;
                案城:
                    的System.out.println(城市);
                    打破;
                案拉链:
                    的System.out.println(邮编);
                    打破;
            }
        }
    }

在哪里boolValue()返回TextUtils.isEmpty(场)的状态,但是这一部分,我不知道该怎么做了,现在RequireFileds是一个枚举:

 公共枚举RequireFields {
    名(姓名,1),
    姓氏(姓,2),
    电子邮件(电子邮件,3)
    PASS(通行证,4)
    CITY(城市,5)
    STREET(街,6)
    的邮政编码(拉链,7);    私人最终字符串字段;
    私人最终诠释位置;    RequireFields(字符串字段,INT位置){
        this.field =领域;
        this.position =位置;
    }    公共字符串getfield命令(){
        回场;
    }    公众诠释为getPosition(){
        返回的位置;
    }}

我把号码与名字,这样我就可以用一个迭代。
任何想法或一个简单的方法来做到这一点?

PD:这是code为我在其他应用程序使用的两个领域:

  ssid.setError(NULL);
    pass.setError(NULL);    。字符串SSID = ssid.getText()的toString();
    字符串传递= pass.getText()的toString()。    布尔取消= FALSE;
    查看focusView = NULL;    如果(TextUtils.isEmpty(PASS)及&放大器;!openWifi){
        pass.setError(的getString(R.string.error_field_pass));
        focusView =传递;
        取消= TRUE;
    }    如果(TextUtils.isEmpty(SSID)){
        ssid.setError(的getString(R.string.error_field_ssid));
        focusView = SSID;
        取消= TRUE;
    }


解决方案

我检查做这个空的EditText ...

 如果(editTextName.getText()。的toString()。equalsIgnoreCase())
{
      //显示消息/土司空名称
}
否则如果(editTextSurname.getText()。的toString()。equalsIgnoreCase())
{
     //显示消息/土司空姓
}
否则如果(editTextEmail.getText()。的toString()。equalsIgnoreCase())
{
     //显示消息/土司空电子邮件
}
其他
{
     //如果以上所有条件都是假的是所有字段不为空所以把你这里的行动
}

希望这有助于..

I'm trying to program a simple register application, the user have to fill some fields, where some of them are obligatory. So, I need to check if the user write the info there. I'm doing this:

    for(RequireFields r : RequireFields.values()){
        if(boolValue()){
            switch (r.getField()) {
                case "name":
                    System.out.println("Name");
                    break;
                case "surname":
                    System.out.println("Surname");
                    break;
                case "pass":
                    System.out.println("Pass");
                    break;
                case "email":
                    System.out.println("Email");
                    break;
                case "street":
                    System.out.println("Street");
                    break;
                case "city":
                    System.out.println("City");
                    break;
                case "zip":
                    System.out.println("Zip");
                    break;
            }
        }
    }

Where boolValue() return the status of TextUtils.isEmpty(Field), but this part I don't know how to do it, RequireFileds for now is an enum:

public enum RequireFields {
    NAME("name",1),
    SURNAME("surname",2),
    EMAIL("email",3),
    PASS("pass",4),
    CITY("city",5),
    STREET("street",6),
    ZIP("zip",7);

    private final String field;
    private final int position;

    RequireFields(String field, int position) {
        this.field = field;
        this.position = position;
    }

    public String getField() {
        return field;
    }

    public int getPosition() {
        return position;
    }

}

I put a number with the name, so I can use an iterate for.Any ideas or a easy way to do this?

PD: This is the code for two fields that I used on other app:

    ssid.setError(null);
    pass.setError(null);

    String SSID = ssid.getText().toString();
    String PASS = pass.getText().toString();

    boolean cancel = false;
    View focusView = null;

    if (TextUtils.isEmpty(PASS) && !openWifi) {
        pass.setError(getString(R.string.error_field_pass));
        focusView = pass;
        cancel = true;
    }

    if (TextUtils.isEmpty(SSID)) {
        ssid.setError(getString(R.string.error_field_ssid));
        focusView = ssid;
        cancel = true;
    }
解决方案

I do this for checking empty EditText...

if (editTextName.getText().toString().equalsIgnoreCase(""))
{
      // show message/toast for empty name
}
else if (editTextSurname.getText().toString().equalsIgnoreCase(""))
{
     // show message/toast for empty Surname
}
else if (editTextEmail.getText().toString().equalsIgnoreCase(""))
{
     // show message/toast for empty Email
}
else
{
     // If above all conditions are false means all fields are not empty so put your action here
}

Hope this help..

这篇关于检查空文本编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 06:30