Toast Message 不消失

Toast Message does not disappear

我有一个 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;
}