Event similar to c # keyDown that can be applied on Android

3

What I need is to capture the Qr and show the records of that code. I have something like that. This is my XAML.

  <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:layout_below="@+id/textView34"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/etcodigoUpdateProducto"
    android:onClick="BuscarProducto"
    android:hint=" Ingreso de   código  por  medio del  lector: " />

This is my code in Java.

public void BuscarProducto(View view)
{
    AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(this,"Adminbase",null,1);
    SQLiteDatabase db= admin.getWritableDatabase();
    String Code=et1.getText().toString();
    fila=db.rawQuery("select Familia,PartNumber,CapacidadCaja,CapacidadPallet,Ubicacion  from  Producto where Code='"+Code+ "'",null);
    if (fila.moveToFirst())
    {
        et2.setText(fila.getString(0));
        et3.setText(fila.getString(1));
        et4.setText(fila.getString(2));
        et5.setText(fila.getString(3));
        et6.setText(fila.getString(4));
    }
    else
    {
        Toast.makeText(getApplicationContext(),"No  existe  un producto  con dicho código",Toast.LENGTH_SHORT).show();
        db.close();
    }
}
    
asked by Sofia 05.01.2017 в 22:30
source

1 answer

1

You can use onSingleTapUp() of OnGestureListener :

 @Override
    public boolean onSingleTapUp(MotionEvent event) {
        Log.d(DEBUG_TAG, "onSingleTapUp: " + event.toString());
        //Key Down!
        return true;
    }

or setOnKeyListener that you assign to a view:

view.setOnKeyListener(new View.OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
            if((event.getAction() == KeyEvent.ACTION_DOWN)) {
                //Key Down!
                return true;
            }
            return false;
        }
});
    
answered by 05.01.2017 / 23:00
source