So habe ich diesen Code:keine Elemente in den ArrayAdapter
suggestionsAdapter.clear();
locations.clear();
List<Predictions> predictions = gson.fromJson(jsonObject.getJSONArray("predictions").toString(), new TypeToken<List<Predictions>>(){}.getType());
for(Predictions prediction : predictions){
String title = prediction.terms.get(0).value;
locations.add(title);
suggestionsAdapter.add(title);
}
Log.i("","loc are:" + locations);
Log.i("","locations are:" + locations.size());
suggestionsAdapter.notifyDataSetChanged();
Log.i("","suggestion adapter size:" + suggestionsAdapter.getCount());
Und ich wieder dieses:
03-30 10:55:56.474: I/(3185): loc are:[Albert Cuypstraat, Albert Cuyp Market, Albania, Alblasserdam, Albert Cuypstraat]
03-30 10:55:56.474: I/(3185): locations are:5
03-30 10:55:56.474: I/(3185): suggestion adapter size:0
Warum ist das passiert? PS: Dies geschieht innerhalb eines Listeners, der die Vorhersagen aus einer Google Places-Abfrage zurückerhält. geändert:
suggestionsAdapter.addAll(locations);
suggestionsAdapter.notifyDataSetChanged();
Noch gleiche Ergebnis, manchmal bekomme ich:
03-30 11:03:25.876: I/(10409): loc are:[Albert Cuypstraat, Albert Cuyp Market, Albert Cuypstraat, AH Haarlemmerdijk, Albert Heijn]
03-30 11:03:25.876: I/(10409): locations are:5
03-30 11:03:25.876: I/(10409): suggestion adapter size:3
Warum fügen Sie einen nach dem anderen Titel in suggestionsAdapter.add (...)? –
Ursache Ich bekam das gleiche Ergebnis für suggestionsAdapter.addAll (Standorte); Und ich sagte, ich werde versuchen, sie einzeln hinzuzufügen –
rufen Sie einfach 'notifyDataSetChanged();' innerhalb 'suggestionsAdapter.add (...)' –