@Override public void run() { String rootLocationName = "", locationName = "", userName = "", calibrate = "", resultTime = ""; if (((String) listTypeSpinner.getSelectedItem()).equals("WIFI")) { if (!wifiDetector.getListDetectedLocation().isEmpty()) { for (Location rootLocation : wifiDetector.getListDetectedLocation().keySet()) { if (!wifiDetector.getListDetectedLocation().get(rootLocation).isEmpty()) { Date date = (new Date(lastGetResultTime)); resultTime = "No_" + countInt + "-Time_" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); rootLocationName = rootLocation.getLocationName(); locationName = wifiDetector .getListDetectedLocation() .get(rootLocation) .get(0) .getLocationName(); userName = rootLocation.getUserName(); int size = wifiDetector.getListDetectedLocation().get(rootLocation).size(); if (wifiDetector.getListDetectedLocation().get(rootLocation).get(size - 1) == null) { calibrate = "not yet"; } else if (convertCheckbox.isChecked()) { calibrate = "already"; } // only return the first location break; } else { Date date = (new Date(lastGetResultTime)); resultTime = "No_" + countInt + "-Time_" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); rootLocationName = "Unknown"; locationName = "Unknown"; } } } } else { if (!gpsDetector.getListDetectedLocation().isEmpty()) { for (String rootLocation : gpsDetector.getListDetectedLocation().keySet()) { if (!gpsDetector.getListDetectedLocation().get(rootLocation).isEmpty()) { Date date = (new Date(lastGetResultTime)); resultTime = "No_" + countInt + "-Time_" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); rootLocationName = rootLocation; locationName = gpsDetector .getListDetectedLocation() .get(rootLocation) .get(0) .getLocationName(); // only return the first location break; } else { Date date = (new Date(lastGetResultTime)); resultTime = "No_" + countInt + "-Time_" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); rootLocationName = "Unknown"; locationName = "Unknown"; } } } } locationNameText.setText(locationName); rootLocationText.setText(rootLocationName); userNameText.setText(userName); calibrateText.setText(calibrate); resultTimeText.setText(resultTime); }