我在drawable中有一些图像存储,在string(value)中有这些图像存储的说明。如果我扫描代码,我希望它显示图像并解释这些图像。例如,我扫描一个代码,然后显示“花”,然后显示花和花的说明。
我试图使一张图像不加说明地出现仍然不起作用。这是我尝试过的:
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();
}
}
}
您是否知道该怎么做?对不起基本问题。我是android新手。谢谢您的帮助。
答案 0 :(得分:1)
使用equals
比较两个字符串:
if(scanContent.equals("water")) {
Intent intent1 = new Intent(this, ShowImage.class);
intent.putExtra("image", R.drawable.water);
startActivities(intent1);
}