Je suis resté avec le problème suivant: Je dois valider, que la valeur de EditText est un entier entre 1 et 1000. Si ce n'est pas - je devrais mettre une partie de la valeur par défaut dans le EditText. Lorsque j'essaie de faire une chose avec le code suivant - j'arrive à la boucle infinie (enfin, c'était prévisible). J'ai vérifié les questions similaires, mais je n'arrive toujours pas à comprendre comment faire fonctionner le code.
Existe-t-il d'autres moyens de mettre en œuvre le comportement souhaité? Comment je devrais éditer mon code pour y parvenir?
Valider EditerTexte
Long mailIntervalValue;
EditText etMailInterval;
.
.
.
.
etMailInterval=(EditText)findViewById(R.id.et_mail_check_interval);
etMailInterval.setText(mailIntervalValue.toString());
etMailInterval.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
Integer t=Integer.getInteger(s.toString());
if (t==null){
s.clear();
s.append(mailIntervalValue.toString());
mailIntervalValue=MessageManager.DEFAULT_TIME;
}
else
mailIntervalValue=t.longValue();
if (mailIntervalValue<1 || mailIntervalValue>1000){
if (mailIntervalValue<1)
mailIntervalValue=1L;
else
mailIntervalValue=1000L;
s.clear();
s.append(mailIntervalValue.toString());
Toast.makeText(MainActivity.this, MainActivity.this.getString(R.string.settings_timer_fail),
Toast.LENGTH_SHORT).show();
}
saveMailerPrefs();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){}
});
Merci, je pense que c'est ce dont j'avais besoin. – Dirol
Bienvenue. J'espère que ça marche pour toi. –