gpt4 book ai didi

java - Toast Message 不消失

转载 作者:行者123 更新时间:2023-11-30 10:42:25 26 4
gpt4 key购买 nike

我有一个 for 循环,我正在其中做一些搜索工作。我想在过程不成功时显示 toast 消息。我可以显示 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;
}

最佳答案

从 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;
}

关于java - Toast Message 不消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38141959/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com