Android- Come implementare il testo Watcher, esempio
-
13-12-2019 - |
Domanda
Ho un programma in cui ho più editext e un finale finale .... Voglio implementare TextWatcher per riflettere le modifiche nel totale editext. Ma non so come implementare tutto questo per le modifiche in piùedittexts.
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
total+=new Integer(s.toString());
_EDTotal.setText(""+total);
}
.
Nell'esempio sopra affronterò un problema ... Quando inserisco il valore al primo se se se se se se se se se se se se se se se se se se se se se se se se se se se se se se se se se settando il valore corretto in _edtotal, ma se cancellai (utilizzare Backspace) nell'editText usando l'ascoltatore non lo faròessere in grado di sostituirlo con un nuovo problema.
Soluzione
Prova così:
edittext.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void afterTextChanged(Editable s) {
//your action
}
});
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow