java - ArrayList TextInput 等于条件不显示用户输入的内容
问题描述
所以我的数组中有 3 个从 API 获取的对象,在我的情况下,当用户输入一些文本并且文本输入的值将与促销名称(下图的底行)进行比较时,它将显示促销名称屏幕上。但是当我输入文字时,它只会显示第二个位置(HELLO),我该如何解决这个当我输入像PROMOBERKAH这样的文字时它会显示PROMOBERKAH,当我输入JULICERIA时它会显示JULICERIA?谢谢。
这是我的条件代码,
public void onTextChanged(CharSequence s, int start, int before, int count) {
for (int i=0;i<ar1.size();i++) {
if (ar1.contains(edtVoucherCode.getText().toString())) {
int position = ar1.indexOf(edtVoucherCode.getText().toString());
codeNotFound.setText("Kode promo berhasil digunakan");
codeNotFound.setTextColor(Color.parseColor("#1ECBB5"));
codeNotFound.setVisibility(View.VISIBLE);
isValid = true;
usePromoPrivateId = jsonData.get(position).getId_promo();
usePromoPrivateName = jsonData.get(position).getPromo_name();
if (jsonData.get(position).getPromo_type().equals("1")) {
usePromoPrivateDiscount = jsonData.get(position).getValue_based();;
} else {
usePromoPrivateDiscountPrice = jsonData.get(position).getValue_based();;
}
} else {
codeNotFound.setText("Kode promo tidak ditemukan");
codeNotFound.setTextColor(Color.parseColor("#DF2C2E"));
codeNotFound.setVisibility(View.VISIBLE);
isValid = false;
}
}
}
解决方案
通过将 indexOf 添加到我的条件代码来解决
int position = ar1.indexOf(edtVoucherCode.getText().toString());
推荐阅读
- python - python中是否有一个命令可以让你重新执行刚刚执行的函数?
- java - 如何将视频从 IP 摄像机传递到 Youtube 上的 LiveStream?
- serverless-framework - 无服务器 provider.environment 变量在自定义中不可用
- r - 检查表中是否存在 Customer_Id 的先前条目并返回其状态
- xamarin.forms - 如何正确地将包含 pdf 的 Webview 重定向到 Google Drive
- r - 将不同的值(按组)添加到 R 中数据框中的另一个值
- r - data.table foverlaps 如何从 x 和 y 返回所有范围?
- google-sheets - 如何在 Google 表格中查询不包含 #N/A 错误的结果
- c# - 如何在具有非托管客户端的 .NET COM DLL 上使用绑定重定向?
- javascript - 在 JavaScript 中比较足够接近的数字