title: Recyclerview Recycled viewholders merging
body: <p>I have a recycler view.  I have many view holders for different content types.</p>
  
  <p>I create my holders like this:</p>
  
  <pre><code>  /**
       * Create instance of
       * compatible viewholder
       *
       * @param viewType
       * @param parent
       * @return
       */
      private AbstractHolder createAbstractHolder(int viewType, ViewGroup parent) {
          AbstractHolder holder = null;
  
          switch (viewType) {
              case VersyConstants.HOLDER_TYPE_1:
                  holder = ViewHolder_Var1.create(parent, mUserHomeFragment, mUserStreamFragment);
  
                  break;
  
              case VersyConstants.HOLDER_TYPE_2:
                  holder = ViewHolder_Var2.create(parent, mUserHomeFragment, mUserStreamFragment);
                  break;
  
              case VersyConstants.HOLDER_TYPE_3:
                  holder = ViewHolder_Var3.create(parent, mUserHomeFragment, mUserStreamFragment);
                  L.i(getClass().getSimpleName(), "HOLDER 3");
                  break;
  
              case VersyConstants.HOLDER_TYPE_4:
                  holder = ViewHolder_Var4.create(parent, mUserHomeFragment, mUserStreamFragment);
                  L.i(getClass().getSimpleName(), "HOLDER 4");
                  break;
  
              case VersyConstants.HOLDER_TYPE_5:
                  holder = ViewHolder_Var5.create(parent, mUserHomeFragment, mUserStreamFragment);
                  L.i(getClass().getSimpleName(), "HOLDER 5");
                  break;
  
              case VersyConstants.HOLDER_TYPE_6:
                  holder = ViewHolder_Var6.create(parent,  mUserHomeFragment, mUserStreamFragment);
                  L.i(getClass().getSimpleName(), "HOLDER 6");
                  break;
  
              case VersyConstants.HOLDER_TYPE_7:
                  holder = ViewHolder_Var7.create(parent, mUserHomeFragment, mUserStreamFragment);
                  L.i(getClass().getSimpleName(), "HOLDER 7");
                  break;
  
              case VersyConstants.HOLDER_TYPE_8:
                  holder = ViewHolder_Var8.create(parent, mUserHomeFragment, mUserStreamFragment);
                  L.i(getClass().getSimpleName(), "HOLDER 8");
                  break;
  
              case VersyConstants.HOLDER_TYPE_9:
                  holder = ViewHolder_Var9.create(parent, mUserHomeFragment, mUserStreamFragment);
                  break;
  
              case VersyConstants.HOLDER_TYPE_10:
                  holder = ViewHolder_Var10.create(parent, mThumbnailViewToLoaderMap, mUserHomeFragment, mUserStreamFragment);
          }
          return holder;
      }
  </code></pre>
  
  <p>The issue is I have when I scroll my recycler view down, and for example view holder 3 is created for the 1st item and the 5th item, when I scroll back up to item no. 1, it has recycled view holder from 5th item, which I know is the idea of the recycler view.</p>
  
  <p>In the viewholders I am hiding/showing textviews if the relevant data comes in JSON.  I am displaying hash tags if present, so in my first item below:<a href="https://i.stack.imgur.com/Ql3Fa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ql3Fa.png" alt="Recyclerview item 1 - no tags"></a></p>
  
  <p>Then when I scroll down to the 5th item which has tags (below):<a href="https://i.stack.imgur.com/b4R5k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b4R5k.png" alt="Recyclerview 5th item with tags"></a></p>
  
  <p>Then when I scroll back up to the first item the tags are added when they shouldn't be as there's no tag data associated with this object (see below):</p>
  
  <p><a href="https://i.stack.imgur.com/o6BTy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o6BTy.png" alt="First item  now with tags"></a></p>
  
  <p>I have debugged and there isn't a mix up in object data, there are no tags added via code, this is down to recyclerview recycling, both of these items have the same view holder (view holder 3).  Is there anyway to prevent this?</p>
  
  <p>Below is the method to populate the tags.  Depending on list size I set visibility of text view to visible and populate:</p>
  
  <pre><code> protected void populateTags(List&lt;String&gt;tags, TextView[] array){
          for(int i=0;i&lt;tags.size(); i++){
              array[i].setText(tags.get(i));
              array[i].setVisibility(View.VISIBLE);
          }
      }
  </code></pre>
  
  <p>I call the above like this <code>List&lt;String&gt; tagsList = feedContent.getTags(); if(tagsList.size&gt;0)populateTags(tagsList, tagsArray);</code>
  This doesn't just happen with item 1 &amp; 5, it depends on which views are being reused.  If there is a view reused for a view already displaying tags, the tags from the reused view are added.  Its very bad</p>