【发布时间】:2018-11-22 12:07:16
【问题描述】:
这是我正在尝试做的代码的一部分,请任何人帮助我,我是 android 开发的新手
这是我得到的确切错误: java.lang.IllegalStateException:适配器的内容已更改,但 ListView 没有收到通知。确保适配器的内容不是从后台线程修改的,而只是从 UI 线程修改的。确保您的适配器在其内容更改时调用 notifyDataSetChanged()。 [在 ListView(2131165289, class android.widget.ListView) with Adapter(class android.widget.ArrayAdapter)]
ListView requestListView;
ArrayList<String> requests = new ArrayList<String>();
ArrayAdapter arrayAdapter;
LocationManager locationManager;
LocationListener locationListener;
ArrayList<Double> requestLatitude = new ArrayList<Double>();
ArrayList<Double> requestLongitude = new ArrayList<Double>();
ArrayList<String> UserNames = new ArrayList<String>();
Button refresh;
public void updateListView(Location location){
if(location!=null) {
requests.clear();
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Request");
final ParseGeoPoint geoPointLocation = new ParseGeoPoint(location.getLatitude(), location.getLongitude());
query.whereNear("location",geoPointLocation);
query.whereDoesNotExist("driverUserName");
query.setLimit(10);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if(e==null){
if(objects.size()>0){
requests.clear();
requestLongitude.clear();
requestLatitude.clear();
for (ParseObject object:objects){
ParseGeoPoint requestLocation = (ParseGeoPoint) object.get("location");
if(requestLocation!=null) {
Double distanceinMiles = geoPointLocation.distanceInKilometersTo(requestLocation);
Double DistanceOneDP = (double) Math.round(distanceinMiles * 10) / 10;
requests.add(DistanceOneDP.toString() + "Km");
arrayAdapter.notifyDataSetChanged();
requestLatitude.add(requestLocation.getLatitude());
requestLongitude.add(requestLocation.getLongitude());
UserNames.add(object.getString("username"));
}
}
}else{
requests.clear();
requests.add("No Near By request");
}
arrayAdapter.notifyDataSetChanged();
}
}
});
}
}
【问题讨论】:
标签: android