OkHttp在一个RecyclerView中显示2个请求

时间:2018-10-07 21:34:05

标签: android okhttp3

我正在尝试完成一个项目,该项目需要使用tmdb api并在RecyclerView中显示结果。问题是,我只能请求电影或电视节目。我似乎找不到一种将两者合并到一个RecyclerView中的方法。下面是我处理请求的方法。

SELECT d AS Date,
CASE WHEN CONVERT(DATE,d) = CONVERT(DATE,GetDate()) Then 'Today' 
    WHEN CONVERT(DATE,d) = DATEADD(DD,-1,CONVERT(DATE,GetDate())) Then 'Yesterday'
    Else 'No' End AS 'Today'
FROM
(
  SELECT d = DATEADD(DAY, rn -1, DATEADD(DD,-60,CONVERT(DATE,GETDATE())))
  FROM 
  (
    SELECT TOP (DATEDIFF(DAY, DATEADD(DD,-61,CONVERT(DATE,GETDATE())),  GETDATE())) 
      rn = ROW_NUMBER() OVER (ORDER BY s1.[object_id])
    FROM sys.all_objects AS s1
    CROSS JOIN sys.all_objects AS s2

    ORDER BY s1.[object_id]
  ) AS x
) AS y

这是我的适配器:

private void generateCall(Request request) {
    Call call = client.newCall(request);
    call.enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {
            Log.d(TAG, "failed");
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            try {
                String jsonData = response.body().string();
                if (response.isSuccessful()) {
                    adapter = new MovieAdapter(getMovieData(jsonData),SelectionActivity.this);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            recyclerView.setLayoutManager(new LinearLayoutManager(SelectionActivity.this));
                            recyclerView.setAdapter(adapter);
                        }
                    });
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}

}

我尝试制作一个单独的List并也使用.addAll()。任何见识将不胜感激!

0 个答案:

没有答案