I have performed many procedures and I have not found the solution for several days with this error. I am making an application in which various products are registered, which I want to take the bar code by means of a scanner with the camera of the mobile phone and save the data in a BD in firebase, if I manually enter the barcode correctly registers the product, the error happens when I scan I want to obtain the code through the sacnner, and I get it but somehow the Registrar button is disabled and I can not register the product but manually if
This is my Layout
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondo"
tools:context="com.example.castalv.adminpos.NuevoProducto">
<LinearLayout
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/nuevo"
android:text="Nuevo Producto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="34dp"
android:layout_marginTop="15dp"
android:textAlignment="center"
android:layout_gravity="center"
android:textStyle="italic" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="@drawable/logo"
/>
</LinearLayout>
<LinearLayout
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/edtCodigoP"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="18dp"
android:textColor="@color/negro"
android:hint="Ingresa el codigo del producto"/>
<Button
android:id="@+id/btnEscaner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Escanear" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/edtNombreP"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="18dp"
android:textColor="@color/negro"
android:hint="Ingresa el nombre del producto"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/edtDescripcionP"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:inputType="textMultiLine"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="18dp"
android:textColor="@color/negro"
android:hint="Ingresa la descripcion del producto"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<EditText
android:id="@+id/edtPrecioP"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="18dp"
android:inputType="number"
android:textColor="@color/negro"
android:hint="Precio compra"/>
<EditText
android:id="@+id/edtPrecio1P"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="18dp"
android:inputType="number"
android:textColor="@color/negro"
android:hint="Precio venta1"/>
</LinearLayout>
<LinearLayout
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/edtPrecio2P"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="18dp"
android:inputType="number"
android:textColor="@color/negro"
android:hint="Precio venta2"/>
<EditText
android:id="@+id/edtPrecio3P"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="18dp"
android:inputType="number"
android:textColor="@color/negro"
android:hint="Precio venta3"/>
</LinearLayout>
<LinearLayout
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/edtCantidadP"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="18dp"
android:inputType="number"
android:textColor="@color/negro"
android:hint="Cantidad"/>
<EditText
android:id="@+id/edtFechaP"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="18dp"
android:inputType="date"
android:textColor="@color/negro"
android:hint="Fecha de Compra"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/btnIngresar"
android:text="Registrar"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:layout_marginTop="40dp"
android:layout_centerHorizontal="true"
android:background="#2E64FE"
android:textSize="18dp"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="wrap_content" />
</LinearLayout>
This is my code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nuevo_producto);
edtCodigoP = (EditText)findViewById(R.id.edtCodigoP);
edtNombreP = (EditText)findViewById(R.id.edtNombreP);
edtDescripcionP = (EditText)findViewById(R.id.edtDescripcionP);
edtPrecioP = (EditText)findViewById(R.id.edtPrecioP);
edtPrecio1P = (EditText)findViewById(R.id.edtPrecio1P);
edtPrecio2P = (EditText)findViewById(R.id.edtPrecio2P);
edtPrecio3P = (EditText)findViewById(R.id.edtPrecio3P);
edtCantidadP = (EditText)findViewById(R.id.edtCantidadP);
edtFechaP = (EditText)findViewById(R.id.edtFechaP);
btnIngresar = (Button)findViewById(R.id.btnIngresar);
btnEscanear = (Button)findViewById(R.id.btnEscaner);
final DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference().child("Productos");
btnIngresar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NuevosProd prod = new NuevosProd(edtCodigoP2,edtNombreP.getText().toString(),
edtDescripcionP.getText().toString(), edtPrecioP.getText().toString(),edtPrecio1P.getText().toString(),
edtPrecio2P.getText().toString(),edtPrecio3P.getText().toString(),edtCantidadP.getText().toString(),
edtFechaP.getText().toString());
dbRef.child(edtNombreP.getText().toString()).setValue(prod);
Toast.makeText(NuevoProducto.this, "Producto registrado", Toast.LENGTH_SHORT).show();
finish();
}
});
btnEscanear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Escanear(view);
}
});
}
private void Escanear(View view) {
vistaEscaner = new ZXingScannerView(this);
vistaEscaner.setResultHandler(this);
setContentView(vistaEscaner);
vistaEscaner.startCamera();
}
public void handleResult (final Result result){
String dato = result.getText();
setContentView(R.layout.activity_nuevo_producto);
vistaEscaner.startCamera();
edtCodigoP = (EditText)findViewById(R.id.edtCodigoP);
edtCodigoP.setText(dato);
}
}
Wherever I send to call the scanner
private void Scan (View view) { vistaScanner = new ZXingScannerView (this); vistaScaner.setResultHandler (this); setContentView (vistaScanner); vistaScanner.startCamera (); }
And here the value returns to show it in my EditText
public void handleResult (final Result result) { String data = result.getText (); setContentView (R.layout.activity_new_product); vistaScanner.startCamera (); edtCodigoP = (EditText) findViewById (R.id.edtCodigoP); edtCodigoP.setText (data); }
Here is the structure of my BD in Firebase