Is there any way to redraw all items of RecyclerView
?
I have some Themes (in style.xml) and after changing the theme, I need the RecyclerView
to be redrawn.
So I want a method that will force to re-call onCreateViewHolder
for each items of the adapter.
I tried to:
adapter.notifyDataSetChanged
but onCreateViewHolder
is not calledrecyclerView.setVisibility(View.GONE)
and then recyclerView.setVisibility(View.VISIBLE)
recyclerView.invalidate()
recyclerView.setAdapter(null)
and then recyclerView.setAdapter(adapter)
.I mention that the RecyclerView
is attached to an Activity, not to a Fragment.
I found the answer! The correct way to do this is:
recyclerView.setAdapter(null);
recyclerView.setLayoutManager(null);
recyclerView.setAdapter(myAdapter);
recyclerView.setLayoutManager(myLayoutManager);
myAdapter.notifyDataSetChanged();
After that, all the items are getting the new style!