ListAdapter中的ListAdapter(List<item>, Context)无法应用于(List<item>)
ListAdapter (List<item>, Context) in ListAdapter cannot be applied to (List<item>)
我正在尝试使用 retrofit2 从 API 获取项目,但我收到此错误 "ListAdapter (List, Context) in ListAdapter cannot be applied to (List)"
onResponse 方法出错。
这是代码。
Activity
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 (List, Context) in ListAdapter cannot be applied to
(List)"
缺少参数。
您应该将 CurrentActivity 名称 作为 第二个参数 传递。
ListAdapter adapter = new ListAdapter(listData.getListItems(),Your_Current_Activity_Name.this);
我正在尝试使用 retrofit2 从 API 获取项目,但我收到此错误 "ListAdapter (List, Context) in ListAdapter cannot be applied to (List)"
onResponse 方法出错。
这是代码。
Activity
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 (List, Context) in ListAdapter cannot be applied to (List)"
缺少参数。
您应该将 CurrentActivity 名称 作为 第二个参数 传递。
ListAdapter adapter = new ListAdapter(listData.getListItems(),Your_Current_Activity_Name.this);