我想做一个小应用程序,让用户在文本框中输入条形码编号。然后他可以扫描条形码,如果文本框中的条形码编号与扫描的条形码匹配,则会显示一条小消息,说“匹配”。
出于某种原因,即使我给出了我正在扫描的确切条形码编号,我输入的条形码也找不到匹配项。我究竟做错了什么?
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//retrieve scan result
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
String scanContent = scanningResult.getContents();
//String scanFormat = scanningResult.getFormatName();
contentTxt.setText(scanContent);
doSomething();
}
else{
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
//Output a message if the barcode matches the code stated in 'scanContent'
public void doSomething(){
if (codeNumber.getText() == contentTxt.getText()) {
Toast toast = Toast.makeText(getApplicationContext(), "We have a match!", Toast.LENGTH_LONG);
toast.show();
}
else {
Toast toast = Toast.makeText(getApplicationContext(), "DOES NOT MATCH!", Toast.LENGTH_LONG);
toast.show();
}
}