>
O comando setOnKeyListener não está funcionando no meu aparelho celular Samsung S5 Versão do Android 5.0 não efetua a busca e no AVD do Android Studio funciona perfeitamente.
Já tentei o setOnEditorActionListener e mesmo assim não funcionou.
Como arrumar este erro ?
Segue abaixo as linhas de comando igual a aula 5
final EditText txtBusca = (EditText) findViewById(R.id.txtBusca);
txtBusca.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
String[] busca = new String[]{"%" + txtBusca.getText().toString() + "%"};
Cursor cursor = db.query("clientes", new String[]{"_id", "nome", "email"},"nome LIKE ?", busca, null, null, "_id DESC", null);
String[] campos = {"_id","nome"};
int[] ids = {R.id.txtId, R.id.txtNome};
SimpleCursorAdapter adt = new SimpleCursorAdapter(getBaseContext(), R.layout.model_clientes, cursor, campos, ids,0);
ListView ltwDados = (ListView) findViewById(R.id.ltwdados);
ltwDados.setAdapter(adt);
return false;
}
});
Wilson
Tente utilizar o addTextChangedListener
Neste link tem um exemplo. No exemplo, é criado uma classe implementando a TextWatcher
http://stackoverflow.com/questions/18503809/set-addtextchangedlistener-in-a-function-android