0

i'm new to Android apps. I'm trying to create a barcode scanner, but the result does not appear in my edittext.

Also, in the onActivityResult the following error is shown:

The method onActivityResult(int, int, Intent) from the type new View.OnClickListener(){} is never used locally

I have the class intentIntegrator and IntentResult in my project.

This a part of my code:

BtnBar.setOnClickListener(new View.OnClickListener() {           
   @Override
   public void onClick(View v) {            
      Intent intent = new Intent("com.google.zxing.client.android.SCAN");
      startActivityForResult(intent, 0);                            
   }               
   public void onActivityResult(int requestCode, int resultCode, Intent data) {;        
     if (resultCode == Activity.RESULT_OK && requestCode == 0) {
        Bundle extras = data.getExtras();
        String result = extras.getString("SCAN_RESULT");            
        EditText desc = (EditText) findViewById(R.produto.desc);
        desc.setText(result);         
     }
     desc.setText(resultCode);
  }     
  //public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  }
 );

This is the XML code for the button:

    <EditText 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+produto/desc"
    android:enabled="false"
    />
<requestFocus />
4

1 回答 1

1

You need to move the onActivityResult method out into the activity rather than inside the setOnClickListener.

The hint that you are getting from the ide (eclipse I presume) is telling you that onActivityResult is never being used by your code base, this is because it is not in the correct place to be picked up by the activity when the:

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
startActivityForResult(intent, 0);   

code path returns.

于 2013-08-10T06:56:26.977 回答