2013-05-02 5 views
0

Я создаю простое приложение для показа спутниковой информации GPS-датчика. Информация показывает, что текст и список никогда не перестают обновляться с помощью той же информации повторения. Как я сохраняю уникальную информацию о сателлитах? Не повторяйте эту же информацию.Как избежать повторной спутниковой информации в списке?

public void onGpsStatusChanged() { 

    GpsStatus gpsStatus = locationManager.getGpsStatus(null); 
    if(gpsStatus != null) { 
     Iterable<GpsSatellite>satellites = gpsStatus.getSatellites(); 
     Iterator<GpsSatellite>sat = satellites.iterator(); 
     int i=0; 
     while (sat.hasNext()) { 
      GpsSatellite satellite = sat.next(); 
      strGpsStats+= (i++) + ": " + "Pseudo-random number for the satellite: "+satellite.getPrn() + "," + "Satellite was used by the GPS calculation: " + satellite.usedInFix() + "," + "Signal to noise ratio for the satellite: "+satellite.getSnr() + "," + "Azimuth of the satellite in degrees: "+satellite.getAzimuth() + "," +"Elevation of the satellite in degrees: "+satellite.getElevation()+ "\n\n"; 
     } 

     Satinfos.setText(strGpsStats); 
    } 
} 

ответ

1

Я думаю, ваша проблема в том, что вы не очистив strGpsStats между каждым вызовом к onGpsStatusChanged; хотя не уверен, потому что ваш вопрос не очень ясен. Попробуйте следующее:

public void onGpsStatusChanged() { 
    strGpsStats = ""; 
    GpsStatus gpsStatus = locationManager.getGpsStatus(null); 
    if(gpsStatus != null) { 
     Iterable<GpsSatellite>satellites = gpsStatus.getSatellites(); 
     Iterator<GpsSatellite>sat = satellites.iterator(); 
     int i=0; 
     while (sat.hasNext()) { 
      GpsSatellite satellite = sat.next(); 
      strGpsStats+= (i++) + ": " + "Pseudo-random number for the satellite: "+satellite.getPrn() + "," + "Satellite was used by the GPS calculation: " + satellite.usedInFix() + "," + "Signal to noise ratio for the satellite: "+satellite.getSnr() + "," + "Azimuth of the satellite in degrees: "+satellite.getAzimuth() + "," +"Elevation of the satellite in degrees: "+satellite.getElevation()+ "\n\n"; 
     } 

     Satinfos.setText(strGpsStats); 
    } 
} 
0

После входа в то время необходимо проверить наличие повторной информации.

while (sat.hasNext()) { 
      GpsSatellite satellite = sat.next(); 
      if(sat.Current != sat.next) 
{ 
      strGpsStats+= (i++) + ": " + "Pseudo-random number for the satellite: "+satellite.getPrn() + "," + "Satellite was used by the GPS calculation: " + satellite.usedInFix() + "," + "Signal to noise ratio for the satellite: "+satellite.getSnr() + "," + "Azimuth of the satellite in degrees: "+satellite.getAzimuth() + "," +"Elevation of the satellite in degrees: "+satellite.getElevation()+ "\n\n"; 
     } 
} 
+0

Может понадобиться Array? если данные (i ++)! = данные (i) – user2342687

+0

sat.Current не существует! – user2342687