0

I have an Adapter for a RecyclerView. The adapter has a property size, that can be either SMALL or LARGE.

Depending on the property, the layouts loaded for viewholders will be different.

I have a button to change this property, however after I set it, and if I call notifyDataSetChanged() the views are not updated.

I have also tried requestLayout and invalidate without success. This is, onCreateViewHolder is never called again.

htafoya
  • 18,261
  • 11
  • 80
  • 104

3 Answers3

0

notifyDataSetChanged() call onBindViewHolder() when using RecyclerView.It doesnot call onCreateViewHolder. You can try setAdapter() for the above problem.

GAGAN BHATIA
  • 591
  • 5
  • 17
0

One way to do is like calling

recyclerView.setAdapater(new YourCustomRecylcerViewAdapter(yourProperty, listToUpdate))

whenever you change the property. This will invoke the onCreateViewHolder() of adapter.

taug
  • 378
  • 1
  • 8
0

Well I got it, it was because before onCreateViewHolder, getItemViewType is called.

If no new view is set then it won't be called. So I had to create a new viewType for each of the small views and problem solved :).

htafoya
  • 18,261
  • 11
  • 80
  • 104