2017-08-18 7 views
1

テキストユーザーの入力後にテキストフィールドのエラーがクリアされない。TextInputレイアウトでエラーメッセージがクリアされない

エラーメッセージを追加すると、それは編集テキストの下に配置され、すべてが良好に見えます。

ここでは最初のユーザー名を入力しましたが、まだテキスト入力レイアウトの下にエラーが表示されています。

enter image description here

コード:

if(!TextUtils.isEmpty(display_name) && !TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)){ 

    mRegProgress.setTitle("Registering User"); 
    mRegProgress.setMessage("Please wait...."); 
    mRegProgress.setCanceledOnTouchOutside(false); 
    mRegProgress.show(); 

    register_user(display_name, email, password); 

}else{ 

    if (mDisplayName.getEditText().getText().toString().length() == 0) 
    { 
     mDisplayName.setErrorEnabled(true); 
     mDisplayName.setError("Please Provide Your Name!"); 
    } 
    else if ((!android.util.Patterns.EMAIL_ADDRESS.matcher(mEmail.getEditText().getText().toString()).matches()) && mEmail.getEditText().getText().toString().length() == 0) 
    { 
     mEmail.setErrorEnabled(true); 
     mEmail.setError("Please Provide Valid Email Address!"); 
    } 
    else if (mPassword.getEditText().getText().toString().length() == 0) 
    { 
     mPassword.setErrorEnabled(true); 
     mPassword.setError("Please Provide Password!"); 
    } 

    else{ 
     if (mDisplayName.getEditText().getText().toString().length() > 0){ 
      mDisplayName.setError(null); 
      mDisplayName.setErrorEnabled(false); 
     } 

     else if(mEmail.getEditText().getText().toString().length() > 0){ 
      mEmail.setError(null); 
      mEmail.setErrorEnabled(false); 
     } 
     else if(mPassword.getEditText().getText().toString().length() == 0){ 
      mPassword.setError(null); 
      mPassword.setErrorEnabled(false); 
     } 
    } 
} 
+0

私はそこにあなたの中括弧で何が起こっているのか分からない - 私は、レイアウトを編集したとき、私はいくつかを削除 - にそれらを見てください。それがあなたのコードに合っていることを確認してください。 –

答えて

0

あなたはそれらの値を取得した後、あなたのテキスト入力をクリアする必要があります - あなたは、彼らが値を持って確認しているとき。それらが最初のelseが実行された後に値がない場合。

if(!TextUtils.isEmpty(display_name) && !TextUtils.isEmpty(email) && 
!TextUtils.isEmpty(password)){ 

    mRegProgress.setTitle("Registering User"); 
    mRegProgress.setMessage("Please wait...."); 
    mRegProgress.setCanceledOnTouchOutside(false); 
    mRegProgress.show(); 

    register_user(display_name, email, password); 
    // This is where you reset your text inputs and other bits and pieces. 
    // If this is true nothing beyond here is executed!! 

}else{ 

ので、何よりも、あなたのロジックを移動:

if(!TextUtils.isEmpty(display_name) && !TextUtils.isEmpty(email) && 
!TextUtils.isEmpty(password)){ 

    mRegProgress.setTitle("Registering User"); 
    mRegProgress.setMessage("Please wait...."); 
    mRegProgress.setCanceledOnTouchOutside(false); 
    mRegProgress.show(); 

    register_user(display_name, email, password); 
    // This is where you reset your text inputs and other bits and pieces. 
    // Start your logic to validate the input here 
    if (mDisplayName.getEditText().getText().toString().length() == 0){ 
     .../... 

}else{ 
    // Put your logic here if there is no input. 
関連する問題