我有一个for循环,并且正在其中进行一些搜索。我想在过程不成功时显示吐司消息。我可以显示吐司消息,但是当我再次搜索时它不会消失。
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;
}
最佳答案
从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;
}