当有适当的最小整数值时,我试图做出一些指示。例如:当变量“round_min” = 10 -> 有一些指令。当“round_min” = 100 -> 还有另一条指令时。
我尝试实现在 HashMap 中查找最小值的函数。 例如:我在HashMap中有两个元素。并且找到了最小值,并且它在 TextView 中正确显示。
但是当我想将这个变量“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
}
}
有人可以帮我找到问题所在以及如何解决吗?
最佳答案
移动所有行
// 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
在最后,第二个 } 之后,这样你就在循环之外了
关于java - HashMap:它在TextView中显示最小值,但min_variable有更多值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42565397/