Emma Mfinanga
Emma Mfinanga

Reputation: 51

How to add String list view ArrayAdapter<String>

am scan Qr code/Barcode, so I want to scan different qr code/barcode and arrange them is String listview.

Example I want to setText() like this ,scanNumber1,scanNumber2,....,..., so far i have managed to scan that Qr Code/Barcode but when i scan the next number it remove the first one, so I want ti arrange those number.

here is my code

public void scanCode(View view){
    IntentIntegrator intentIntegrator = new IntentIntegrator(this);
    intentIntegrator.initiateScan();

}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

    IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
       String scanNumber=intentResult.getContents();
    if (intentResult != null) {

        if(intentResult.getContents() == null) {

            Toast toast = Toast.makeText(getApplicationContext(), "Scan The QR code/Barcode", Toast.LENGTH_LONG);
            toast.show();

        }
        //validate ur scan numbers
        else if (intentResult.getContents().length() == 10) {
            textView1.setText(intentResult.getContents());
        }
        else if(intentResult.getContents().length() == 12){
            textView2.setText(intentResult.getContents());
        }
        else {
            Toast toast = Toast.makeText(getApplicationContext(), "That Number is Out Of Our Range", Toast.LENGTH_LONG);
            toast.show();
        }
    }

    super.onActivityResult(requestCode, resultCode, data);

}

and this is output enter image description here

so I want on that Slave to appear like ,scanNumber1,scanNumber2,....,...,

Upvotes: 0

Views: 57

Answers (1)

Chetan Gupta
Chetan Gupta

Reputation: 1647

you can use a global JointoString function object to achieve the desired behaviour i.e. "barcode1","barcode2"....

ArrayList<String> results = new ArrayList<String>()

when you receive the result try

results.add(<value>)

while displaying to text view use

textView.setText(results.joinToString(","))

Upvotes: 1

Related Questions