title: how to make the header of Recycle view invisible
body: <p>I have a Recyclerview with <code>header view as slider images</code> and remaining view as <code>normal recycler items</code>.I am wondering if there is any way around to make the header view invisible depending upon some sort of condition.The recycler view consists of two separate layout files for this purpose: <code>layout1</code> for header items and <code>layout2</code> for normal recycler items and adapter will pick a layout and binds corresponding data at runtime.</p>
  
  <p>This is my RecyclerView adapter <code>RestaurantAdapter.java</code></p>
  
  <pre><code>    public class RestaurantAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
  
          private static final String TAG = RestaurantAdapter.class.getName();
          private List&lt;Restaurant&gt; mList;
          private Context mContext;
          private RestaurantType mRestaurantType;
          private static final int RECYCLER_HEADER=0,RECYCLER_ITEMS=1;
          private LayoutInflater inflater;
          private SlideItemViewHolder slideItemViewHolder;
          private List&lt;ImageSliderPOJO&gt; mData;
  
          public RestaurantAdapter(Context context, List&lt;Restaurant&gt; list, RestaurantType restaurantType) {
              this.mContext = context;
              this.mList = list;
              this.mRestaurantType = restaurantType;
              inflater=LayoutInflater.from(context);
  
          }
  
          public void updateAdapter(List&lt;ImageSliderPOJO&gt; data){
              this.mData = data;
              this.notifyDataSetChanged();
          }
  
  
          @Override
          public int getItemCount() {
              return mList.size();
          }
  
          @Override
          public int getItemViewType(int position) {
              return position == 0 ? RECYCLER_HEADER : RECYCLER_ITEMS;
          }
  
          @Override
          public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, final int i) {
              int viewType=viewHolder.getItemViewType();
              switch (viewType){
                  case RECYCLER_HEADER:
                      slideItemViewHolder = (SlideItemViewHolder) viewHolder;
                      slideItemViewHolder.updateHeader();
                      break;
  
                  case RECYCLER_ITEMS:
                      final RecyclerItemViewHolder holder = (RecyclerItemViewHolder) viewHolder;
                      final Restaurant restaurant = mList.get(i);
                      Picasso.with(mContext)
                              .load(restaurant.getVendorLogo())
                              .placeholder(R.mipmap.ic_launcher)
                              .error(R.mipmap.ic_launcher)
                              .into(holder.restaurentImageView);
  
                      holder.restaurentNameTextView.setText(restaurant.getName());
                   //Remaining code here
  
                      break;
  
                  default:
                      throw new RuntimeException(TAG+":Unable to bind the viewType"+viewType);
  
              }
          }
  
          @Override
          public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
  
              switch (viewType){
                  case RECYCLER_HEADER:
                      return new SlideItemViewHolder(inflater.inflate(R.layout.slide_show_restaurant_fragment_list,viewGroup,false));
  
                  case RECYCLER_ITEMS:
                      return new RecyclerItemViewHolder(inflater.inflate(R.layout.new_restautant_list_items, viewGroup, false));
  
                  default:
                    throw new RuntimeException(TAG+":Invalid ViewType "+viewType);
              }
  
          }
  
          public static class RecyclerItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
              private ClickListener clickListener;
               //Initialization here.
  
  
              public RecyclerItemViewHolder(View v) {
                  super(v);
                  ButterKnife.inject(this, v);
                  v.setOnClickListener(this);
  
  
              }
  
              @Override
              public void onClick(View v) {
                  clickListener.onClick(v, getPosition(), false);
              }
  
              public interface ClickListener {
  
                  /**
                   * Called when the view is clicked.
                   *
                   * @param v           view that is clicked
                   * @param position    of the clicked item
                   * @param isLongClick true if long click, false otherwise
                   */
                  public void onClick(View v, int position, boolean isLongClick);
  
              }
  
              /* Setter for listener. */
              public void setClickListener(ClickListener clickListener) {
                  this.clickListener = clickListener;
              }
          }
  
  
          // id = 87,170
  
          private class SlideItemViewHolder extends RecyclerView.ViewHolder {
              SliderLayout sliderLayout;
              LinearLayout rootLinearLayout;
              public SlideItemViewHolder(View recyclerHeader) {
                  super(recyclerHeader);
                  sliderLayout = (SliderLayout) recyclerHeader.findViewById(R.id.home_slider);
                  rootLinearLayout = (LinearLayout) recyclerHeader.findViewById(R.id.rootLinearLayout);
              }
  
              private void updateHeader() {
                  if(Util.isNetworkAvailable(mContext)){
                      for (int i = 0; i &lt; mData.size(); i++) {
                          DefaultSliderView defaultSliderView = new DefaultSliderView(mContext);
                          final int finalI = i;
                          defaultSliderView.image(mData.get(finalI).getImageUrl())
                                  .setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() {
                                      @Override
                                      public void onSliderClick(BaseSliderView slider) {
                                          Restaurant restaurantById = Restaurant.searchByRestaurantId(mData.get(finalI).getTargetVendorId());
                                          if(restaurantById != null)
                                              openDetailFragment(restaurantById);
                                      }
                                  });
                          sliderLayout.addSlider(defaultSliderView);
                      }
                  }
  
  
              }
  
          }
  
  
          public void openDetailFragment(Restaurant restaurant) {
              Intent intent = new Intent(mContext, DetailTabActivity.class);
              intent.putExtra(DetailTabActivity.INTENT_RESTAURANT_DATA, restaurant);
              mContext.startActivity(intent);
  
          }
  
          public SliderLayout getSliderLayout(){
              return slideItemViewHolder.sliderLayout;
          }
      }
  </code></pre>
  
  <p>And this adapter is set and updated from this fragment <code>RestaurantFragment.java</code> as:</p>
  
  <pre><code>private void setAdapter()  {
          dismissDialog();
          if (getActivity() != null)
              getActivity().runOnUiThread(new Runnable(){
                  @Override
                  public void run() {
                      if (restaurantList != null &amp;&amp; restaurantList.size() &gt; 0) {
                          restaurantRecyclerView.setVisibility(View.VISIBLE);
                          mEmptyListTextView.setVisibility(View.GONE);
                          restaurentListAdapter = new RestaurantAdapter(getActivity(), restaurantList, mRestaurantType);
                          restaurantRecyclerView.setAdapter(restaurentListAdapter);
                          restaurentListAdapter.updateAdapter(mData);
  
                          restaurantRecyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener(mLayoutManager) {
                              @Override
                              public void onLoadMore(int current_page) {
  
                                  mCurrentPage = mCurrentPage + 1;
                                  getHttpResturantData();
                              }
                          });
                      }
                  }
              });
      }
  </code></pre>
  
  <p>Is this much of an explanation helpful or should I paste more code?</p>