1
I have a barcode reader that does the action of putting the text in edittext and pressing enter automatically, I implemented the function while reading but I would like the focus on edittext to continue. My code :
final EditText codBarras = (EditText) activity.findViewById(R.id.codigoBarras);
codBarras.requestFocus();
codBarras.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (i == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
SQLiteDatabase dbr = banco.getReadableDatabase();
Cursor cursor = dbr.rawQuery("SELECT _id FROM produto WHERE codigo_barra = '"+codBarras.getText().toString()+"'", null);
if (cursor.getCount() > 0){
cursor.moveToFirst();
addItens(cursor.getInt(cursor.getColumnIndex("_id")));
}
codBarras.setText("");
codBarras.requestFocus();
}
return false;
}
});
Even with requestFocus the edittext focus changes.
I have the same problem, but I have two separate topics: Autofocus in Edittext does not work and Run function with ENTER in Edittext
– rbz
Brother if I can get the answer put in your question :D
– Brenddon Anjos
We are looking for the same solution. Now that I understand what you want ! rs
– rbz
I published the answer there
– Brenddon Anjos