0
I’m servicing an android app made with Eclipse(ADT).
There is a text box, where the barcode of the product will be typed, as well as this reading can be done with the reader. When you open Activity, if you enter a value in the text box, the event onKey
is fired twice(up and down). If "enter" is entered a search is performed; the search method focuses on the next box and deletes the CB when completed. This works the first time, both typing and using the reader(the reader gives a enter at the end).
The problem is: if I try to read or enter another barcode, the events are not triggered. No log is generated. It will only be fired if I press the Backspace key.
txtProduto.setOnKeyListener(new OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
Log.i("keycode", Integer.toString(keyCode));
if ((keyCode == KeyEvent.KEYCODE_ENTER)) {
executarPesquisa();
return true;
}
return false;
}
});
There are some other events that I don’t know what it’s for, I don’t know if it’s affecting. I’ve commented on them and it doesn’t solve.
txtProduto.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
strFocus = "P";
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtProduto.getWindowToken(), 0);
}
});
This run query calls the method execute
of a class that implodes AsyncTask<Void, Integer, Integer>
Take the event keylistener and treat in the event focuschange this out of question?
– Reginaldo Rigo
It will not. Once the barcode is read, you need to fire the search. I need you to identify enter to perform the search. The player "gives" the enter. The way it works only once.
– user26552
If the reader gives the enter, the setOnFocusChangeListener event occurs. In this event you can call the query. It would not be feasible?
– Reginaldo Rigo
I’ll take a look and tell you
– user26552