【发布时间】:2025-12-20 18:10:12
【问题描述】:
我正在尝试使用 retrofit2 从 API 获取项目,但我收到此错误“ListAdapter (List, Context) in ListAdapter cannot be applied to (List)”
错误在于 onResponse 方法。
这里是代码。
活动
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 请将上下文作为第二个参数传递
标签: java android android-recyclerview android-context