I needed to have two types on Views on my RecyclerView Adapter as well, one for 'regular' mode and one for multi-select mode.
So, you can override getItemViewType to force the Adapter to call your onCreateViewHolder for all views.
Add this to the Adapter code:
public void setActionMode(ActionMode actionMode) {
this.actionMode = actionMode;
notifyDataSetChanged();
}
@Override
public int getItemViewType(int position) {
return (actionMode == null ? 0 : 1);
}
Add this to the ViewHolder:
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
if (viewType == 0) {
view = inflater.inflate(R.layout.layout_1, parent, false);
} else {
view = inflater.inflate(R.layout.layout_2, parent, false);
}
...
}
Since you return a different ViewType when in an ActionMode, the Adapter is forced to throw away all created views, and recreate everything again.