【发布时间】:2020-11-19 22:27:29
【问题描述】:
我的程序有一个需要始终聚焦的编辑文本字段,但由于某种原因,在它检测到数据重复并将其删除后,它应该重新聚焦但它没有。
下面的此代码检查代码是否与最后扫描的 5 个代码重复。如果没有重复,则将其添加到最后添加的 5 个代码中,然后将其发送到数据库(这里没问题,该部分效果很好),如果重复,则清除该字段并尝试重新关注编辑文本,但这里是代码失败的地方。
注意事项:
txtmanualbarcode 是一个编辑文本。
setInputType(inputType.Type_NULL) 隐藏了不需要的键盘。
scanneditems是最后5个代码的数组列表。
allscanneditems 是完整的代码列表。
如果需要进一步的代码或解释,请询问我,这个错误已经拖了我好几天了。
public void addScannedItem(final QrScannedItem it) {
boolean duplicado = false;
for (int a = 0; a < scannedItems.size(); a++) {
if (scannedItems.get(a).qr_code.compareTo(it.qr_code) == 0) {
txtmanualbarcode.setText("");
txtmanualbarcode.clearFocus();
txtmanualbarcode.requestFocus();
txtmanualbarcode.setInputType(InputType.TYPE_NULL);
duplicado = true;
}
}
if (!duplicado) {
scannedItems.add(0, it);
if (scannedItems.size() > 5) {
scannedItems.remove(5);
allScannedItems.add(0, it);
}
runOnUiThread(new Runnable() {
public void run() {
adapter.notifyDataSetChanged();
}
});
showProgressBar();
Thread thr = new Thread() {
public void run() {
try {
String state = status.compareTo("in") == 0 ? "1" : "0";
String time = getScanTime();
JSONObject obj = QrCourseServer.checkin(state, it.qr_code, time, course.id, AppCache.currentUser.token);
String msg = obj.getString("message");
it.extraMessage = msg;
if (msg.toLowerCase().compareTo("socio") == 0) {
//play socio beep
playMp3Resource(R.raw.ding);
} else {
//play no socio beep
playMp3Resource(R.raw.dingdong);
}
} catch (Exception ex) {
Log.e(TAG, "Exception: " + ex.getMessage());
it.extraMessage = ex.getMessage();
playMp3Resource(R.raw.error);
//UIHelper.msbox("Error",ex.getMessage(),ScanActivity.this);
} finally {
closeProgressBar();
runOnUiThread(new Runnable() {
public void run() {
adapter.notifyDataSetChanged();
txtmanualbarcode.setText("");
txtmanualbarcode.requestFocus();
txtmanualbarcode.setInputType(InputType.TYPE_NULL);
}
});
}
}
};
thr.start();
} else {
txtmanualbarcode.requestFocus();
}
}
我的问题(可能)存在于第一个 for 循环中。
【问题讨论】:
标签: java android android-listview android-edittext