title: Android RecyclerView shows multiple items at same position
body: <p>I am having a number of weird things happen in my RecyclerView class that I believe are all connected. First, here is my implementation:</p>
  
  <p><strong>onCreateViewHolder</strong></p>
  
  <pre><code>@Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  
      LayoutInflater inflater = LayoutInflater.from(parent.getContext());
      padding = parent.getResources().getDimensionPixelSize(R.dimen.rec_padding);
  
      switch (viewType) {
  
          case USER:
  
              View userView = inflater.inflate(R.layout.user_view, parent, false);
              return new UserViewHolder(userView);
  
          case POST:
  
              View postView = inflater.inflate(R.layout.post_view, parent, false);
              return new PostViewHolder(postView);
  
          default:
  
              return null;
      }
  }
  </code></pre>
  
  <p><strong>onBindViewHolder</strong></p>
  
  <pre><code>@Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
  
      switch (holder.getItemViewType()) {
  
          case USER:
  
              UserViewHolder userViewHolder = (UserViewHolder) holder;
              User user = (User) items.get(position);
  
              if (position == 0) {
  
                  userViewHolder.recCard.setPadding(0, padding, 0, 0);
              }
  
              //Get relevant date for user
  
              if (user.getExpanded()) {
  
                  userViewHolder.details.setVisibility(View.VISIBLE);
              }
  
              userViewHolder.showDetails.setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View view) {
  
                      if (userViewHolder.details.getVisibility() != View.VISIBLE) {
  
                          userViewHolder.details.setVisibility(View.VISIBLE);
                          user.setExpanded(true);
                      } else {
  
                          userViewHolder.details.setVisibility(View.GONE);
                          user.setExpanded(false);
                      }
                  }
              });
  
              break;
  
          case POST:
  
              PostViewHolder postViewHolder = (PostViewHolder) holder;
              Post post = (Post) items.get(position);
  
              if (position == 0) {
  
                  postViewHolder.recCard.setPadding(0, padding, 0, 0);
              }
  
              //Get relevant date for post
  
              break;
      }
  }
  </code></pre>
  
  <p>So the problems I'm having:</p>
  
  <p>1) I am adding padding to the top of only the first item in the list. This is working as expected for the first item. However, once I start scrolling the padding is eventually added to the top of other items in the list. My assumption is that once I reach a certain point in the list of items, a new item is at position 0, so it also gets the extra padding.</p>
  
  <p>2) I am trying to save certain properties about each item in the RecyclerView, particularly whether they are expanded or not. I am doing that by storing their expanded state as a boolean in the object itself and then retrieving it within <code>onBindViewHolder</code>. This isn't working though—similar to above, other items in the list are also showing up as expanded once I scroll. So the expanded state isn't be preserved properly.</p>