我正在尝试使用.equals()将字符串与对象属性进行比较,但条件始终失败,即使其为true。 我试过使用trim()摆脱尾随空格,但仍然失败。
这里是我的代码:
if (status) {
inventoryList = allInventory.getInventory();
assert assetId != null;
for (Inventory inventory : inventoryList) {
if (assetId.trim().equals(inventory.getProductCode().trim())) {
//get the current quantity that exists
new_quantity.setValue(0);
new_quantity.setMaxValue(inventory.getQuantity());
inventoryId = inventory.getId();
return;
} else {
// new_quantity.setVisibility(View.GONE);
decrement.setEnabled(false);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Product not found ");
// prevent cancel of AlertDialog on click of back button and outside touch
alert.setCancelable(false);
alert.setMessage("Product is not in inventory. Do you want to continue scanning?");
alert.setNegativeButton("No", (dialog, which) -> {
onBackPressed();
dialog.dismiss();
}
);
alert.setPositiveButton("Yes", (dialog, which) -> {
Intent scanAsset = new Intent(this, ScanActivity.class);
scanAsset.putExtra("building", building);
scanAsset.putExtra("room", room);
scanAsset.putExtra("department", depart);
scanAsset.putExtra("TAG", "E");
startActivity(scanAsset);
dialog.dismiss();
});
AlertDialog dialog = alert.create();
dialog.show();
}
}