我正在使用Volley
进行Api调用并将数据设置为RecyclerView
。我有我的第一个Volley,其中我获得了ID字段,并使用相同的ID进行了另一个Api调用。我同时使用了两个api调用的响应并将数据设置为RecyclerView,但是第二个Api调用的响应未同时设置在Recyclerview上,后来我手动刷新选项卡并从数据库的集合中设置数据。
这是我嵌套的Volley
Api呼叫
private void getData() {
final JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, ApiUrls.FirstCall, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
if (response != null) {
for (int i = 0; i < response.length(); i++) {
JSONObject object = response.getJSONObject(i);
CurrentStatusEntry entry = new CurrentStatusEntry();
String Id= object.getString("id");
id_url = ApiUrls.Info+ Id + "/";
JsonObjectRequest foodie_request = new JsonObjectRequest(Request.Method.GET, id_url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String name=response.getString("name");
String address=response.getString("address");
entry.setName(name);
entry.setAddress(address);
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
})
AppController.getInstance().addToRequestQueue(foodie_request, foodie_data_req);
current.add(entry);
if (current.size() > 0) {
adapter = new QueueAdapter(current, getActivity().getApplicationContext());
recyclerView.setAdapter(adapter);
}
}
}
} catch (JSONException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
})
AppController.getInstance().addToRequestQueue(request, restqueue_req);
}
第二个api调用的数据未立即设置。如何执行此操作?