I am making an application where I enter the user's code through a manual scanner, I need to fire an event just when it EditText
receives the barcode data.
Deactivate the option to receive data through the keyboard so that it is not displayed.
This is my java code .
edtEmployeeID.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Toast.makeText(getApplicationContext(), edtEmployeeID.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
Although I have not entered it using the scanner.
in xml
<EditText
android:id="@+id/edtEmployeeID"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:singleLine="true"
android:hint="@string/code"
android:textColorHint="@color/colorSecundaryText"
android:textSize="25sp"
android:textAlignment="center"
android:textColor="@color/colorPrimaryText"
android:cursorVisible="false"
android:focusable="true"/>
Well, in the end, I opted to change the method and use
addTextChangedListener()
it to detect a change within theEditText
, and it worked just as I wanted.