title: How to hide/display specific RecyclerView item?
body: <p>I have a contacts list RecyclerView, where the first item (position 0) holds the user's details. When the search icon in the toolbar is pressed, I want that entry to be hidden from the user. </p>
  
  <p>I've tried using <code>setVisibility(View.GONE)</code> on it, and, although the entry is hidden, the space it occupied was still there, much like setting <code>setVisibility(View.INVISIBLE)</code>. How can I toggle the visibility of this specific entry to VISIBLE/GONE in my RecyclerView, or how can I set its height only to 0dp?</p>
  
  <p>EDIT:</p>
  
  <p>My xml is quite simple, it comprises of simply a recyclerView and a FAB. My adapter code is as below. </p>
  
  <pre><code>ContactsAdapter(
              Context context,
              List&lt;LinphoneContact&gt; contactsList,
              ContactViewHolder.ClickListener clickListener,
              SelectableHelper helper) {
          super(helper);
          mContext = context;
          updateDataSet(contactsList);
          mClickListener = clickListener;
      }
  
      @NonNull
      @Override
      public ContactViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  
          // For the first position only, use the user's own contact card
          // For all the rest, use the contact card
          switch (viewType) {
              case USER_CARD_VIEW:
                  View userCard =
                          LayoutInflater.from(parent.getContext())
                                  .inflate(R.layout.contacts_user_card, parent, false);
                  return new ContactViewHolder(userCard, mClickListener);
              case CONTACT_CARD_VIEW:
                  View contactCard =
                          LayoutInflater.from(parent.getContext())
                                  .inflate(R.layout.contact_cell, parent, false);
                  return new ContactViewHolder(contactCard, mClickListener);
          }
          return null;
      }
  
      @Override
      public void onBindViewHolder(@NonNull ContactViewHolder holder, int position) {
  
          // Remove the user's card when searching contacts - DOES NOT WORK, MAKES ALL FIRST ITEMS
          // INVISIBLE
          //        if (position == 0) {
          //            if (mIsSearchMode) holder.itemView.setVisibility(View.GONE);
          //            else holder.itemView.setVisibility(View.VISIBLE);
          //        }
  
          if (position != 0) {
  
              LinphoneContact contact = (LinphoneContact) getItem(position - 1);
  
              holder.name.setText(contact.getFullName());
  
              if (!mIsSearchMode) {
                  String fullName = contact.getFullName();
                  if (fullName != null &amp;&amp; !fullName.isEmpty()) {
                      holder.separatorText.setText(String.valueOf(fullName.charAt(0)));
                  }
              }
  
              // Separator as in the big capital letter on the left to indicate sections
              holder.separator.setVisibility(
                      mIsSearchMode
                                      || (getPositionForSection(getSectionForPosition(position))
                                              != position)
                              ? View.GONE
                              : View.VISIBLE);
  
              holder.linphoneFriend.setVisibility(
                      contact.isInFriendList() ? View.VISIBLE : View.GONE);
  
              ContactAvatar.displayAvatar(contact, holder.avatarLayout);
  
              boolean isOrgVisible = LinphonePreferences.instance().isDisplayContactOrganization();
              String org = contact.getOrganization();
              if (org != null &amp;&amp; !org.isEmpty() &amp;&amp; isOrgVisible) {
                  holder.organization.setText(org);
                  holder.organization.setVisibility(View.VISIBLE);
              } else {
                  holder.organization.setVisibility(View.GONE);
              }
  
              holder.delete.setVisibility(isEditionEnabled() ? View.VISIBLE : View.INVISIBLE);
              holder.delete.setChecked(isSelected(position));
              //        } else {
              //            // TODO - user's card should have whole and voicemail onClick listeners
          }
  
          //        Log.d("contactsAdapter", "Position: " + position);
          //        Log.d("contactsAdapter", "Section for position: " +
          // getSectionForPosition(position));
          //        Log.d(
          //                "contactsAdapter",
          //                "The other thingy: " +
          // getPositionForSection(getSectionForPosition(position)));
      }
  
      // +1 item count to account for user's contact card
      @Override
      public int getItemCount() {
          return mContacts.size() + 1;
      }
  
      public Object getItem(int position) {
          if (position &gt;= getItemCount()) return null;
          return mContacts.get(position);
      }
  
      public void setIsSearchMode(boolean set) {
          mIsSearchMode = set;
      }
  
      [...]
  
      @Override
      public int getItemViewType(int position) {
          return position == 0 ? USER_CARD_VIEW : CONTACT_CARD_VIEW;
      }
  
  </code></pre>
  
  <p>Essentially, I don't add the first item to my list of items, but instead I add it to the recyclerView, and shift my list of items by one position up.</p>