<item>ListAdapter 中的 ListAdapter (List, Context) 不能应用于 (List<item>)



我正在尝试使用 retrofit2 从 API 获取项目,但我收到此错误"ListAdapter 中的 ListAdapter (List, Context( 无法应用于 (List(">

错误在响应方法上。

这是代码。

活动

Call<ListData> listDataCall = youTubeApi.getlists(channelId, apiKey);
    listDataCall.enqueue(new Callback<ListData>() {
        @Override
        public void onResponse(Call<PlaylistData> call, Response<PlaylistData> response) {
            int statusCode = response.code();
            ListData listData = response.body();
            Log.d("list", "onResponse: " + statusCode);
            ListAdapter adapter = new ListAdapter(listData.getListItems()); //Error is here
            recyclerView.setAdapter(adapter);
        }
        @Override
        public void onFailure(Call<PlaylistData> call, Throwable t) {
            Log.d("Playlist", "onResponse: " + t.getMessage());
        }
    });

适配器

private final Context context;
private List<ListItem> myPlayList; 
public ListAdapter(List<ListItem> cPlaylist, Context _context) {
    myPlayList = cPlaylist;
    context = _context;
}

"ListAdapter 中的 ListAdapter (List, Context( 不能应用于 (列表(">

缺少参数。

您应该将当前活动名称作为第二个参数传递。

 ListAdapter adapter = new ListAdapter(listData.getListItems(),Your_Current_Activity_Name.this);

最新更新