我有一个for循环,我正在做一些搜索。我想在进程失败时显示toast消息。我可以显示吐司信息但当我想再次搜索时它不会消失。
public String SearchInstallationBySerialNumber(String serial){
String installation = null;
for(int i = 0; i < _allItems.size(); i++){
OsbDownloadItem currentOsbItem = _allItems.get(i);
if(!currentOsbItem.getSerialNumber().equals(serial)){
Toast.makeText(mActivity,
"unsuccessful searching",
Toast.LENGTH_SHORT).show();
continue;
}else{
installation = currentOsbItem.getInstallation();
}
}
return installation;
}
答案 0 :(得分:1)
从for循环中删除Toast可能有所帮助!
public String SearchInstallationBySerialNumber(String serial) {
String installation = null;
for (int i = 0; i < _allItems.size(); i++) {
OsbDownloadItem currentOsbItem = _allItems.get(i);
if (currentOsbItem.getSerialNumber().equals(serial)) {
installation = currentOsbItem.getInstallation();
break;
}
}
if (installation == null) {
Toast.makeText(mActivity, "unsuccessful searching", Toast.LENGTH_SHORT).show();
}
return installation;
}