Call> call = apiService.getData();
call.enqueue(new Callback
>() {
@Override
public void onResponse(Call
> call, Response
> response) {
if (response.isSuccessful() && response.body() != null) {
myDataList = response.body();
myAdapter.notifyDataSetChanged();
} else {
//处理空数据
}
}
});
public void onBindViewHolder(MyAdapter.MyViewHolder holder, int position) { MyDataModel myData = myDataList.get(position); holder.setData(myData); }
通过以上三个步骤,您应该能够正确地使用Retrofit请求来填充RecyclerView适配器。