title: RecyclerView: how to clear cached/recycled views?
body: <p>I use a RecyclerView to display a list of items with a list layout. I switch from a list layout to a grid layout, showing just a subset of all the data when in grid layout. This switch uses a different layout XML than when list layout is presented.  </p>
  
  <p>All this works well, except that when I scroll, recycled (cached?) list layout views populate the grid, mixed in with proper grid layout view items. In other words, instead of using my <code>layout_grid.xml</code> for each item's layout in the RecyclerView, I get items using the <code>layout_list.xml</code> layout, but in a grid format.</p>
  
  <p>This tells me the LayoutManager is working correctly, switching from a list to grid layout. But not all item view items are recreated using the grid xml layout, but rather recycled list layout views are used.</p>
  
  <p>I tried <code>RecyclerView.removeAllViews()</code>, <code>RecyclerView.removeAllViewInLayout()</code>, <code>RecyclerView.swapAdapter()</code> (to force adapter reload), all to no avail.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>If I scroll two positions down in the list, and then switch from list to grid, the first two positions do not go through onCreateViewHolder(), but straight to onBindViewHolder() and are therefore not forced to use the grid layout xml. Instead those first two position items are recycled (I think) and displayed in their list layout format.</p>