I have an editText in my application which has a TextWatcher implemented in the creation of the class
txtBeneficiary = (EditText) findViewById (R.id.txtBeneficiary) txtBeneficiary.addTextChangedListener (filterTextWatcher);
private TextWatcher filterTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence s, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable s) {
CambiarTexto(s.toString());
}
};
private void CambiarTexto(String s) {
txtBeneficiary.addTextChangedListener(filter);
String txtIngreso = s ;
if(contactosCel.contains(txtIngreso)){
int pos = contactosCel.indexOf(txtIngreso);
txtBeneficiary.setText(contactos.get(pos));
}
txtBeneficiary.addTextChangedListener(filterTextWatcher);
}
until here all right, the issue is that by writing many letters quickly, you can see that the process becomes quite slow, until you get stuck, doing a little research, I found that the best way is to put it in a secondary thread, so that the principal does not stop, now try the following
new Thread(new Runnable() {
public void run() {
txtBeneficiary.addTextChangedListener(filterTextWatcher);
}
}).start();
But it has not taken effect, never use multi thread in any language, so any detail to solve this will be very helpful, thank you already