Le paramètre count de la méthode onTextChanged de TextWatcher ne fonctionne pas correctement pour EditText avec le type d'entrée textWebPassword. Le code à l'intérieur d'else if (count == 1) est en cours d'exécution même s'il y a plus de 1 caractères dans EditText.Le paramètre count de la méthode onTextChanged de TextWatcher ne fonctionne pas correctement pour EditText avec le type d'entrée textWebPassword
public class Test extends AppCompatActivity {
private EditText ePassword;
private TextView tPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
tPassword = (TextView) findViewById(R.id.textView_password);
ePassword = (EditText) findViewById(R.id.editText_password);
ePassword.addTextChangedListener(textWatcherPassword);
}
private TextWatcher textWatcherPassword = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count == 0) {
// start fade out animation
tPassword.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out));
//Make the elements invisible
tPassword.setVisibility(View.INVISIBLE);
}
else if(count==1){
// Make fade in elements Visible first
tPassword.setVisibility(View.VISIBLE);
// start fade in animation
tPassword.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in));
}
Log.e("Count", count + "");
}
@Override
public void afterTextChanged(Editable s) {
}
};
}
sortie Logcat est (pour le mot de passe avec plus de 1 caractère):
08-19 16:54:49.465 25167-25167/com.test.example E/Count﹕ 1
08-19 16:54:49.607 25167-25167/com.test.example E/Count﹕ 1
08-19 16:54:49.756 25167-25167/com.test.example E/Count﹕ 1
08-19 16:54:49.881 25167-25167/com.test.example E/Count﹕ 1
08-19 16:54:50.006 25167-25167/com.test.example E/Count﹕ 1
08-19 16:54:50.122 25167-25167/com.test.example E/Count﹕ 1
Utilisez logcat pour enregistrer exactement ce que vous recevez dans 'count', alors vous serez capable de savoir ce qui se passe vraiment. – Sebastian
Après quelques recherches, j'ai eu mon code en cours d'exécution en utilisant s.length() == 1 au lieu de count == 1. – Nischal