I made a search
in my list however it needs me to hit enter to complete the search and show the results. I would like the result to come automatically when typing. Appreciate.
My code:
........
public class ListClientes extends AppCompatActivity implements AdapterView.OnItemLongClickListener, AdapterView.OnItemClickListener {
ListView lista;
ArrayList<Cliente> clientes;
EditText search;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_clientes);
lista = (ListView) findViewById(R.id.listview);
search = (EditText) findViewById(R.id.search);
lista.setOnItemLongClickListener(this);
lista.setOnItemClickListener(this);
atualizar(null);
search.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
atualizar(null);
return false;
}
});
}
public void atualizar(View view) {
ClienteDao cliDao = new ClienteDao();
clientes = cliDao.getListagem(" where nome like '" + search.getText().toString() + "%'");
lista.setAdapter(new ClienteAdapter(getBaseContext(), clientes));
}
........