-2

I have a few image store in drawable and a explanation of those image store in string(value).if i scan a code, i want it show an image and explanation of those image. for example, i scan a code and it shows "flower" then it'll show flower and explanation of flower.

I tried to get one image to appeared without explanation still doesn't work. here's what i've tried :

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    String water;
    IntentResult scanningResult = 
IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);

    if (scanningResult != null) {
        String scanContent = scanningResult.getContents();
        contentTxt.setText(scanContent);
        if(scanContent = water) {
            Intent intent1 = new Intent(this, ShowImage.class);
            intent.putExtra("image", R.drawable.water);
            startActivities(intent1);
        }else{
            Toast toast = Toast.makeText(getApplicationContext(),
                    "comparing failed", Toast.LENGTH_SHORT);
            toast.show(); 
        }

    } else{
        Toast toast = Toast.makeText(getApplicationContext(),
                "No scan data received!", Toast.LENGTH_SHORT);
        toast.show();
    }
}
}

do you have any idea how to do it?sorry for basic question. i'm new in android. thanks for your help.

Juls
  • 17
  • 5

1 Answers1

1

Use equals For Comparing Two Strings:

if(scanContent.equals("water")) {
            Intent intent1 = new Intent(this, ShowImage.class);
            intent.putExtra("image", R.drawable.water);
            startActivities(intent1);
        }
Karishma Patel
  • 469
  • 1
  • 5
  • 16