Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
this i the code i used to just toast the scanned values. i need to show each values in separate editText.
this code opens a scanner
Java
public void onClick(View v) {
			// TODO Auto-generated method stub
			detailList(v);
			try {
	             //start the scanning activity from the com.google.zxing.client.android.SCAN intent

        Intent intent = new Intent(ACTION_SCAN);

        intent.putExtra("SCAN_MODE", "PRODUCT_MODE");

        startActivityForResult(intent, 0);
} catch (ActivityNotFoundException anfe) {

        //on catch, show the download dialog

        showDialog(Primary.this, "No Scanner Found", "Download a scanner code activity?", "Yes", "No").show();

    }

}
		});
}

and this is where i need help, to show the scanned values in editText

<pre lang="java">
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

        if (requestCode == 0) {

            if (resultCode == RESULT_OK) {

                //get the extras that are returned from the intent

                String contents = intent.getStringExtra("SCAN_RESULT");

                String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

                Toast toast = Toast.makeText(this, "Content:" + contents + " Format:" + format, Toast.LENGTH_LONG);

                toast.show();

            }

        }
Posted

1 solution

The same way you would add any text to an EditText control. If you are not sure which method or property to use then a quick look at the documentation[^] should help.
 
Share this answer
 
Comments
Rahul Ramakrishnan 19-May-15 1:34am    
i used 4 edittext here but all four shows the same value. i need GTIN,expiry batch and a serial in each edittext

public void onActivityResult(int requestCode, int resultCode, Intent intent) {

if (requestCode == 0) {

if (resultCode == RESULT_OK) {

//get the extras that are returned from the intent

String contents = intent.getStringExtra("SCAN_RESULT");
String contents1 = intent.getStringExtra("SCAN_RESULT");
String contents2 = intent.getStringExtra("SCAN_RESULT");
String contents3 = intent.getStringExtra("SCAN_RESULT");
gtin.setText(contents.toString());
expiry.setText(contents1.toString());
batch.setText(contents2.toString());
serial.setText(contents3.toString());
Richard MacCutchan 19-May-15 4:58am    
But you are getting the same value in each text control!
Rahul Ramakrishnan 19-May-15 8:18am    
yes
Richard MacCutchan 19-May-15 8:27am    
What do you mean by "yes"? You are capturing the same value in each of your strings above. How do you expect to get different values shown in the text boxes?
Rahul Ramakrishnan 19-May-15 8:40am    
in the 1st editText in need to get a GIT number, in the second expiry number, in the third batch number and 4th serial number. but after scanning i get GIT number in all editText

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900