Actually, I'd like to improve on Anton's answer.
Since getItemViewType(int position)
returns an integer value, you can return the layout resource ID you'd need to inflate. That way you'd save some logic in onCreateViewHolder(ViewGroup parent, int viewType)
method.
Also, I wouldn't suggest doing intensive calculations in getItemCount()
as that particular function is called at least 5 times while rendering the list, as well as while rendering each item beyond the visible items. Sadly since notifyDatasetChanged()
method is final, you can't really override it, but you can call it from another function within the adapter.