Another one is make sure you set layout manager to RecyclerView:
recycler.setLayoutManager(new LinearLayoutManager(this));
Your getItemCount
method returns 0
. So RecyclerView
never tries to instantiate a view. Make it return something greater than 0
.
for example
@Override
public int getItemCount() {
return data.size();
}
i forgot to add below line after i adding it worked for me
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
I really really hope this helps someone someday. I just spent over an hour on this one going nuts!
I had this:
projects_recycler_view.apply {
this.layoutManager = linearLayoutManager
this.adapter = adapter
}
When I should have had this:
projects_recycler_view.apply {
this.layoutManager = linearLayoutManager
this.adapter = projectAdapter
}
Because I foolishly called my adapter adapter
, it was being shadowed by the recycler view's adapter in the apply block! I renamed the adapter to projectAdapter to differentiate it and problem solved!
Please set layout manager to RecyclerView
like below code:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view_right);
//set your recycler view adapter here
NavigationAdapter adapter = new NavigationAdapter(this, FragmentDrawer.getData());
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
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.
Maybe it helps someone but if you set your RecycleView's visibility to GONE the adapter methods won't be called at all... Took me some time to figure it out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With