我打电话进行改造,响应的大小就是我希望作为RecyclerView适配器的主要数据集传递的大小。我可以确认我已成功致电Retrofit。
我很好奇如何将数据集的大小传递给MyAdapter类。下面是我的代码:
在我的主要活动中:
require_once APPPATH.'vendor/autoload.php';
MyAdapter:
call.enqueue(new Callback<List<Recipe>>() {
@Override
public void onResponse(Call<List<Recipe>> call, Response<List<Recipe>> response) {
Log.v("TAG", String.valueOf(response.isSuccessful()));
mRecipeListResponse = response.body();
for (Recipe recipe : mRecipeListResponse){
Log.v("ID", recipe.getId().toString());
}
mAdapter.setDataSet(mRecipeListResponse);
mRecipeList.setAdapter(mAdapter);
; }
@Override
public void onFailure(Call<List<Recipe>> call, Throwable t) {
Log.v("TAG", t.getMessage());
}
});
答案 0 :(得分:3)
我的猜测是您以空MyAdapter
来启动mRecipeDataSet
。尝试以下代码。
private List<Recipe> mRecipeDataSet = new ArrayList<Recipe>();
并替换您的代码
//this is wrong, it doesn't do the right thing as the function name suggests.
public List<Recipe> setDataSet(List<Recipe> recipeList){
return mRecipeDataSet;
}
到
public void setDataSet(List<Recipe> recipeList){
mRecipeDataSet = recipeList;
}