在Android中翻新嵌套的GET请求

时间:2018-12-04 08:57:43

标签: android android-recyclerview retrofit retrofit2

我在应用程序中使用Retrofit。我需要调用两个Web服务来将数据设置为RecyclerView。从第一次JSONArray调用中得到GET。格式为

[
    {
        "id": 2,
        "status": "W",
        "myId": 2
    },
    {
        "id": 1,
        "status": "W",
        "myId": 1
    }
]  

我需要从此myId获取JSONObject,并且需要以http://www.example.com/api/myInfo/myId的身份调用另一个Web服务来获取另一个响应。由于第二个Web服务调用依赖于1,因此我想同时获取数据并将其设置为RecyclerView适配器。目前,我将该服务称为

getCalls.getInfo().enqueue(new Callback<ArrayList<QueuePojo>>() {
            @Override
            public void onResponse(Call<ArrayList<QueuePojo>> call, Response<ArrayList<QueuePojo>> response)
            {
                entry=response.body();
                adapter=new QueueAdapter(entry,MainActivity.this);
                recyclerView.setAdapter(adapter);
                adapter.notifyDataSetChanged();
            }

            @Override
            public void onFailure(Call<ArrayList<QueuePojo>> call, Throwable t) {

            }
        });

如何在翻新中进行这样的依赖调用,最后将数据设置到RecyclerView Adapter?

0 个答案:

没有答案