0

嗨,我有一个登录表单,其中有两个 EditText,一个用于电子邮件,一个用于密码,一个登录按钮,当用户按下按钮时,我想对表单进行一些验证。例如,如果没有在 EditText 中输入任何内容,那么 EditText 的提示颜色和文本就是我迄今为止尝试过的。我明白了,所以它以“”的形式注销,但它并没有改变提示。

Editable emailInputEditable = emailInput.getText();
    String emailInputString = emailInputEditable.toString();
    Editable passwordInputEditable = passwordInput.getText();
    String passwordInputString = passwordInputEditable.toString();

    Log.v("loginForm", "emailInputString = " + emailInputString);
    Log.v("loginForm", "passwordInputString = " + passwordInputString);

    if(emailInputString ==""){emailInput.setHint("Please enter your email");}
    if(passwordInputString ==""){passwordInput.setHint("Please enter your password");}
4

4 回答 4

2

用这个

if(emailInputString.length==0){emailInput.setHint("Please enter your email");}
    if(passwordInputString.length==0){passwordInput.setHint("Please enter your password");}

要禁用登录按钮,请使用以下代码

if(emailInputString.length==0 && passwordInputString.length==0)
signbtn.setVisibility(View.GONE);
于 2013-02-15T12:01:59.237 回答
0

试试这个:

if(emailInputString.equals("")){emailInput.setHint("Please enter your email");}
if(passwordInputString.equals("")){passwordInput.setHint("Please enter your password");}

您将此代码放入按钮单击事件中

于 2013-02-15T12:00:53.700 回答
0

要比较字符串,请使用equals()...

编辑。太晚了 :/

于 2013-02-15T12:04:03.137 回答
0

试试这个..

    if(!TextUtils.isEmpty(emailInput.getText()){

            if(!TextUtils.isEmpty(passwordInput.getText())){

                // Perfom your logic here..

            }else
                passwordInput.setError("Please enter your password");

        }else
            emailInput.setError("Please enter your email..");

快乐编码:)

于 2013-02-15T12:13:07.233 回答