My RecyclerView
does not call onCreateViewHolder
, onBindViewHolder
even MenuViewHolder
constructor, therefore nothing app
This does not apply for your particular case. But this might help someone else.
This reason could be careless usage of the following method
recyclerView.setHasFixedSize(true);
If not used with caution, this might cause the onBindView
and onCreateViewHolder
to not be called at all, with no error in the logs.
My encouter was the onBindViewHolder( holder , position) overrided method of the RecyclerView.adaptor not being called. Method onCreateViewHolder was called, getItemCount was called. If you read the specs for Recyclerview Adapter, you will learn that if you have overrided onBindViewHolder( holder, position, List payloads) will be called in favour. So please be careful.
i forgot to add below line after i adding it worked for me
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
Add this to Your Adapter Class
@Override
public int getItemCount() {
return mDataset.size();
}
See my answer if you are using android data binding library - Make sure you are setting layout for recyclerview and item count must be greater than 0
@BindingAdapter({"entries", "layout"})
public static void setEntries(RecyclerView view, ArrayList<LoginResponse.User> listOfUsers, int layoutId) {
if (view.getAdapter() == null) {
view.setLayoutManager(new LinearLayoutManager(view.getContext()));
SingleLayoutAdapter adapter = new SingleLayoutAdapter(layoutId) {
@Override
protected Object getObjForPosition(int position) {
return listOfUsers.get(position);
}
@Override
public int getItemCount() {
return listOfUsers.size();
}
};
view.setAdapter(adapter);
}
}
Happy coding :-)
For what it's worth, I observed it when I set the recycler view adapter before the adapter was actually initialized. Solution was to make sure recyclerView.setAdapter(adapter)
was called with a non-null adapter