title: Recycler View not saving state of Views
body: <p>I am working on Recycler view in which I am using LinearLayout in adapter. When clicking on LinearLayout it is hiding View and similarly clicking again making it Visible. My problem is that Recycler view is not holding the state of Views, when I am scrolling it is again refreshing View again changing the state Views of initial time.</p>
  
  <p>My RecyclerView code along with my Adapter is given below.</p>
  
  <p>RecyclerView Code:</p>
  
  <pre><code> LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    Menu_Detail_Adapter  searchabledapter = new Menu_Detail_Adapter(getActivity());
     RecyclerView mRecyclerView =(RecyclerView)view.findViewById(R.id.recycler_view);
      mRecyclerView.setHasFixedSize(true);
      mRecyclerView.setItemViewCacheSize(2);
      mRecyclerView.setAdapter(searchabledapter);
      mRecyclerView.setLayoutManager(layoutManager);
  </code></pre>
  
  <p>My Adapter Code:</p>
  
  <pre><code>public class Menu_Detail_Adapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; implements Filterable {
  
  
      public Menu_Detail_Adapter(Context context1) {
          arrayList = new ArrayList&lt;&gt;();
          arrlist = new ArrayList&lt;&gt;();
          context = context1;
      }
  
  
  
  
      @Override
      public RecyclerView.ViewHolder  onCreateViewHolder(ViewGroup parent, int viewType) {
  
  
              View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.kasib_o_karahi_list_view, parent, false);
              return new MemberViewHolder(view, onItemClickListener);
  
      }
  
  
  
      String imageUrl = "";
      @Override
      public void onBindViewHolder(final RecyclerView.ViewHolder  holder, int position) {
  
          final ParseObject parseObject = arrayList.get(position);
  
          if(holder instanceof  MemberViewHolder){
  
              if (arrayList.size() &gt; 0) {
                  try {
  
                      ((MemberViewHolder) holder).linear_layout__add.setVisibility(View.VISIBLE);
                      ((MemberViewHolder) holder).linear_layout_add_subtract_buttons.setVisibility(View.GONE);
  
                      // Here I am facing a problem
  
                      // On both LinearLayout click listeners when I am scrolling it 
  is again changing my View States
  
  
                      ((MemberViewHolder) holder).rrl_add.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              ((MemberViewHolder) holder).linear_layout__add.setVisibility(View.GONE);
                              ((MemberViewHolder) holder).linear_layout_add_subtract_buttons.setVisibility(View.VISIBLE);
                          }
                      });
  
                      ((MemberViewHolder) holder).rrl_minus.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              ((MemberViewHolder) holder).linear_layout__add.setVisibility(View.VISIBLE);
                              ((MemberViewHolder) holder).linear_layout_add_subtract_buttons.setVisibility(View.GONE);
                          }
                      });
  
                      ((MemberViewHolder) holder).rrl_add_btn.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
  
                          }
                      });
  
  
  
                  } catch (Exception e) {
                      e.getMessage();
                  }
              }
          }
      }
  
      @Override
      public int getItemCount() {
          return arrayList == null ? 0 : arrayList.size();
      }
  
      @Override
      public void onAttachedToRecyclerView(RecyclerView recyclerView) {
          super.onAttachedToRecyclerView(recyclerView);
      }
  
      @Override
      public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
          super.onDetachedFromRecyclerView(recyclerView);
      }
  
  
  
  
      static class MemberViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
          TextView txtTitle;
          TextView txtDescription;
          TextView txtCountry;
          OnItemClickListener onItemClickListener;
          ImageView imgDescription;
  
          LinearLayout linear_layout_add_subtract_buttons, linear_layout__add;
          RelativeLayout rrl_add, rrl_minus, rrl_add_btn;
  
          public MemberViewHolder(View itemView, OnItemClickListener onItemClickListener) {
              super(itemView);
              linear_layout_add_subtract_buttons = (LinearLayout) itemView.findViewById(R.id.add_subtract_buttons);
              linear_layout__add                 = (LinearLayout) itemView.findViewById(R.id.ll_add);
              rrl_add              = (RelativeLayout) itemView.findViewById(R.id.rrl_add);
              rrl_minus            = (RelativeLayout) itemView.findViewById(R.id.rrl_minus);
              rrl_add_btn          = (RelativeLayout) itemView.findViewById(R.id.rrl_add_btn);
  
  
              itemView.setOnClickListener(this);
              this.onItemClickListener = onItemClickListener;
          }
  
          @Override
          public void onClick(View v) {
              onItemClickListener.onItemClick(v, getAdapterPosition());
          }
      }
  
      public interface OnItemClickListener {
          void onItemClick(View view, int position);
      }
  
      public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
          this.onItemClickListener = onItemClickListener;
      }
  
  
  }
  </code></pre>