Search code examples
androidandroid-studioqr-codezxing

Different result for zxing QRscanner


I have three different EditText and three different Qr button. Every button setText to each EditText. Can anyone help me about it.

Scanqr function

public void scanQRCode(View view, String from) {
        IntentIntegrator integrator = new IntentIntegrator(this);
        integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
        integrator.setOrientationLocked(true);
        integrator.setCameraId(0);
        integrator.setBeepEnabled(false);
        integrator.setBarcodeImageEnabled(false);
        integrator.addExtra("from", from);
        integrator.initiateScan();
    }

Activity Result

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        final IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (result != null) {
            if (result.getContents() == null) {
                Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
            } else {
                //do any.


            }
        } else {
            // This is important, otherwise the result will not be passed to the fragment
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

can i put something like intent putextra to check which button i click? Hope someone can help please. Thx so much


Solution

  • int clickedButton = 0;
    
    findViewById(R.id.your_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickedButton = 1;
            }
        });
    
    findViewById(R.id.your_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickedButton = 2;
            }
        });
    
    findViewById(R.id.your_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickedButton = 3;
            }
        });
    

    in onActivityResult check if(clickedButton == 1) set the text to particular edittext