我想在適當的最小整數值時做一些說明。例如:當變量「round_min」= 10 - >有一些指令。當「round_min」= 100時 - >有另一條指令。HashMap:它在TextView中顯示最小值,但min_variable有更多值
我試着實現在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
}
}
有人能幫助我找到的問題,以及如何用它弄清楚?
謝謝。有用 :) – gryzek