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.
notifyDataSetChanged() call onBindViewHolder() when using RecyclerView.It doesnot call onCreateViewHolder. You can try setAdapter() for the above problem.
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.
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 :).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.