My RecyclerView
does not call onCreateViewHolder
, onBindViewHolder
even MenuViewHolder
constructor, therefore nothing app
For me, it was because the setHasStableIds(true); method was set. Remove that and it will work
If using a custom adapter do not forget to set the ItemCount to the size of your collection.
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));
In my case, my list size was 0 and it was not calling the onCreateViewHolder method. I needed to display a message at center for the empty list as a placeholder so I did it like this and it worked like charm. Answer by @Konstantin Burov helped.
@Override
public int getItemCount() {
if (contactList.size() == 0) {
return 1;
} else {
return contactList.size();
}
}
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.
In my case I set the ID of my RecyclerView to "recyclerView". It seems that this ID was already defined somewhere, because when I changed that to different ID, the methods from the adapter were called properly.