In the Create of my Activity, I have the following
entidadFinanciera.addTextChangedListener(filterTextWatcher);
which does
private TextWatcher filterTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
// no se necesita
}
@Override
public void onTextChanged(CharSequence s, int i, int i1, int i2) {
// no se necesita
}
@Override
public void afterTextChanged(Editable s) {
filtro(s.toString());
}
};
Filter:
private void filtro(String s) {
entidadFinanciera.removeTextChangedListener(filterTextWatcher);
Spinner spinerBancos = (Spinner) findViewById(R.id.imgpayment);
int cantidad = bancos.size();
bancosCopia = bancos ;
int iterador = 0 ;
final ArrayList<String> bancosAux = new ArrayList<>();
while(iterador<cantidad){
if(bancos.get(iterador).contains(s)){
bancosAux.add(bancos.get(iterador));
}
iterador++;
}
final ArrayAdapter<String> dataAdapte = new ArrayAdapter<>(Registry.this, R.layout.support_simple_spinner_dropdown_item, bancosAux);
dataAdapte.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
spinerBancos.setAdapter(dataAdapte);
spinerBancos.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
Object agencia = dataAdapte.getItem(position);
String agenciaSeleccionada = agencia.toString();
EditText edit = (EditText)findViewById(R.id.txtEntidadFinanciera) ;
numeroDeEntidad = agenciaSeleccionada.substring(0,3).trim();
edit.setText(agenciaSeleccionada.substring(4,agenciaSeleccionada.length()));
bancos = bancosCopia;
}
@Override
public void onNothingSelected(AdapterView<?> adapter) {
// no se necesita
}
});
entidadFinanciera.addTextChangedListener(filterTextWatcher);
}
In a nutshell, I have an EDITTEXT, where I write the filter and load that to a spinner, and once I have chosen something from that SPINNER to place it in the EDITTEXT, but this one remains in an infinite loop, try to eliminate it at the beginning. listener and put it back to the last but still remains a loop