我可能有一个非常愚蠢的问题。
我正在使用Volley库进行网络通信:
getGeocodingResults(finalDepartureUrl, new IVolleyCallback() {
@Override
public void onSuccess(JSONObject jsonObject) {
handleVolleyResponse(jsonObject, order, 1);
}
});
// getGeocodingResults method :
private void getGeocodingResults(String url, final IVolleyCallback iVolleyCallback)
{
RequestQueue queue = Volley.newRequestQueue(getActivity());
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url.toString(), null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
iVolleyCallback.onSuccess(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
// hide the progress dialog
}
});
queue.add(jsonObjReq);
}
handleVolleyResponse方法是一个点 - 我想设置Order的字段值:
private void handleVolleyResponse(JSONObject jsonObject, Order order, int flag) {
/*
* here is JSONObject data parsing
* and now I want set parsed value latlng to Order's object field
*/
synchronized (order) {
switch (flag) {
case 1:
OrdersFragment.getOrdersList().get(OrdersFragment.getOrdersList().indexOf(order)).setDeparturePoint(latLng);
break;
case 2:
OrdersFragment.getOrdersList().get(OrdersFragment.getOrdersList().indexOf(order)).setDestinationPoint(latLng);
/* I tried also like this order.setDestinationPoint(latLng);*/
break;
}
}
}
但是当handleVolleyResponse
完成工作时检查订单的值时,新值不会设置为Order的对象。
OrdersFragment.getOrdersList()是volatile
如何将字段设置为对象?