所以我有这段代码:
String[]
我回来了:
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());
为什么会这样? PS:这发生在一个侦听器中,它从谷歌地方查询中获取预测。 改为:
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
同样的结果,有时我得到:
suggestionsAdapter.addAll(locations);
suggestionsAdapter.notifyDataSetChanged();
答案 0 :(得分:0)
我正在使用AutoCompleteTextView的列表。这就是问题所在。加载列表时,AutoCompleteTextView正在过滤,因此它不会显示响应。 我使用自定义的autoCompleteTextView修复了这个问题,我从这里开始: https://www.codeofaninja.com/2013/12/android-autocompletetextview-custom-arrayadapter-sqlite.html