2016-06-02 7 views
0

ログイン時にTextInputLayoutがあります。ユーザー名が空の場合はログインボタンをクリックし、パスワードが空の場合はエラーを表示してエラーを表示しますが、ユーザー名が空でパスワードが空でない場合時間エラーは表示されませんので、どうすればこの問題を解決できますか?私のコードは以下のようなものです!!!ヌル以来ログイン時にTextInputLayout問題が発生する

@Override 
public void onClick(View v) { 
    Intent mIntent; 
    switch (v.getId()) { 
     case R.id.txtSignIn: 
      hideKeyboard(mActivity, v); 

      if (etUserName.getText().toString().equals("")) { 
       etUserName.requestFocus(); 
       etUserName.setCursorVisible(true); 
       tilPassword.setErrorEnabled(false); 
       tilUserName.setErrorEnabled(true); 
       tilUserName.setError(getString(R.string.username_required)); 
      } else if (etPassword.getText().toString().equals("")) { 
       etPassword.requestFocus(); 
       etPassword.setCursorVisible(true); 
       tilUserName.setErrorEnabled(false); 
       tilPassword.setErrorEnabled(true); 
       tilPassword.setError(getString(R.string.password_required)); 
      } else { 
       tilUserName.setErrorEnabled(false); 
       tilPassword.setErrorEnabled(false); 
       showToast(mActivity, getString(R.string.successfully_login), 0); 
       mIntent = new Intent(SignIn.this, DashBoard.class); 
       startActivity(mIntent); 
      } 
      break; 
     case R.id.txtSignUp: 
      mIntent = new Intent(mActivity, SignUp.class); 
      startActivity(mIntent); 
      break; 
     case R.id.txtForgotPassword: 
      mIntent = new Intent(mActivity, ForgotPassword.class); 
      startActivity(mIntent); 
      break; 
    } 
    try { 
    } catch (Exception e) { 
     LOGD(getClass().getSimpleName(), e.getMessage()); 
     LOGE(getClass().getSimpleName(), e.getMessage()); 
    } 
} 
+0

セットルール(IF !strUsername.isEmpty()&& strPassw.isEmpty())など... –

+0

してみましょう! –

+0

毎回プロジェクトを即座に実行しようとしていますか? – Lawrance

答えて

0

利用のisEmpty()メソッドと「」< - これはEditTextが空であるかどうか、あなたが導き出すことができない等しくありません。以下、このような

何かが画面上にエラーがポップアップ表示されますパスワードまたはユーザ名フィールドのいずれかである空で

if (etUserName.isEmpty() && etPassword.isEmpty()) { 
      <your code if nothing is entered> 
} 

追加のヘルプをチェックするために、このアウト:それらの両方のための Check if EditText is empty.

+0

私もTextUtils.isEmptyを試しました!!! –

+0

その結果は何ですか? TextUtilsはEditTexts isEmptyメソッドとは異なりますTextUtilsではCharSequesnceを明示的に指定する必要があります。 – Newbee

+0

そのまま変更はありません! –

関連する問題