RecyclerView﹕ No adapter attached; skipping layout

I never had this issue and it was really hard to replicate for me. 😺

It is because you aren’t setting empty adapter to RecyclerView first. The blog you give didn’t exactly told how. Here is how I normally write.

My adapter constructor normally looks like this.

public ProfilePhotoRecyclerViewAdapter(Activity context) {
  photos = new ArrayList<>();
  listContext = context;
}

And write public (setter) method for the object array list.

public void setPhotos(List< ModelAttachment> photoList) {
  photos.clear();
  photos.addAll(photoList);
  this.notifyItemRangeInserted(0, photos.size() - 1);
}

And in your fragment, you don’t have to initialise with photo array anymore.

adapter = new ProfilePhotoRecyclerViewAdapter(getActivity());

Just call the setter method from adapter inside your API response’s onCompletion method.

@Override
public void onCompletion(ModelUser result) {
  photoList.clear();
  photoList.addAll(0,user.getPhotos());

  adapter.setPhotos(photoList);
}

I think this might solve. Feel free to ask and discuss.

Cheers,

SH

Leave a Comment