有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java HashMap:它在TextView中显示最小值,但min_变量有更多值

我试图给出一些说明,什么时候会有合适的最小整数值。例如:当变量“round_min”=10->;这里有一些说明。当“圆形_min”=100->;还有另外一个指示

我尝试实现在HashMap中找到最小值的函数。 例如:HashMap中有两个元素。找到最小值,并在文本视图中正确显示

但当我想将这个变量“round_min”用于另一个函数时,hashmap中会显示所有的值。我想一直保持最低限度

下面我给出代码:

int round_min;

// nearestDistances is a hashmap where I put distances
Map.Entry<String, Float> nearestMarker = null;

for (Map.Entry<String, Float> entry : nearestDistances.entrySet()) {    
    if (nearestMarker == null || nearestMarker.getValue() > entry.getValue()) {
        nearestMarker = entry;
        round_min = Math.round(nearestMarker.getValue());
        Log.e(" MIN ", round_min + "");

        // it displays in log.e all values 

        // this function see all values, not only minimum
        DisplayMinimumValue(getApplicationContext(), round_min); 
        Log.e("    ROUND MIN    ", round_min + "");

        tvDistanceToNearest.setText(String.valueOf(round_min)); // there is displaying only minimum value
    }
}

有人能帮我找到问题并解决它吗


共 (1) 个答案

  1. # 1 楼答案

    因为我还不能评论。。。我不确定你的问题是什么。我看到如果你在地图上遇到一个较小的值,你正在更新你的round_min变量。我还看到,有些方法在迭代中使用该变量。项目的哪一部分表现得不像你希望的那样