I'm making an application where I enter the user code by means of a manual scanner, I need to trigger an event just when the EditText
receives the barcode data.
Deactivate the option to receive data through the keyboard so 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"/>