title: how to remove empty list item in recycler views?
body: <p>I'm using recycler view to show items with multiple views. whenever I launch the app some white space is being showed. which is exactly equal to my list items.
  I provided the screenshot please go through it.</p>
  
  <p><a href="https://i.stack.imgur.com/yr1im.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yr1im.jpg" alt="enter image description here"></a></p>
  
  <p>I think there is no problem with my code.
  following is my code
  recyclerview</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".activities.GroupView"&gt;
  &lt;android.support.v7.widget.RecyclerView
      android:id="@+id/recycler_view_group_content"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:scrollbars="vertical" &gt;
  &lt;/android.support.v7.widget.RecyclerView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>adapter code</p>
  
  <pre><code>import android.content.Context;
  import android.support.v7.widget.CardView;
  import android.support.v7.widget.RecyclerView;
  import android.text.TextUtils;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.List;
  import java.util.Objects;
  
  import pdfshare.hemanthreddy.com.pdfshare.R;
  import pdfshare.hemanthreddy.com.pdfshare.pojo.PdfItemHolder;
  import pdfshare.hemanthreddy.com.pdfshare.pojo.RequestPojo;
  
   public class GroupContentAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
  
  final int PDF = 0,REQUEST = 1;
  List&lt;Object&gt; list;
  OnClickListener onClickListener;
  Context context;
  
  public GroupContentAdapter(List&lt;Object&gt; list, OnClickListener onClickListener, Context context) {
      this.list = list;
      this.onClickListener = onClickListener;
      this.context = context;
  }
  
  public class PdfHolder extends RecyclerView.ViewHolder {
  
      TextView pdfName,pdfDescription,Helped,uploadedBy;
      Button downloadPdf,viewPdf;
      View container;
      CardView cardView;
      public PdfHolder(View itemView) {
          super(itemView);
          container = itemView;
          uploadedBy = (TextView) itemView.findViewById(R.id.pdf_info_uplodedby);
          pdfName = (TextView) itemView.findViewById(R.id.pdf_name);
          pdfDescription = (TextView) itemView.findViewById(R.id.pdf_description);
          Helped = (TextView) itemView.findViewById(R.id.helped);
          downloadPdf = (Button) itemView.findViewById(R.id.download_pdf);
          viewPdf = (Button) itemView.findViewById(R.id.view_pdf);
          cardView = (CardView) itemView.findViewById(R.id.card_view_pdf_row);
  
      }
  }
  public class RequestHolder extends RecyclerView.ViewHolder {
      View container;
      TextView name,request;
      public RequestHolder(View itemView) {
          super(itemView);
          container = itemView;
          name = (TextView) itemView.findViewById(R.id.requested_name);
          request = (TextView) itemView.findViewById(R.id.request);
      }
  }
  public interface OnClickListener{
      public void OnItemClick(View view,int position);
  }
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
     RecyclerView.ViewHolder viewHolder;
      LayoutInflater inflater = LayoutInflater.from(parent.getContext());
      switch (viewType) {
          case PDF:
              View v1 = inflater.inflate(R.layout.pdf_row_view,parent,false);
              viewHolder = new PdfHolder(v1);
              break;
          case REQUEST:
              View v2 = inflater.inflate(R.layout.group_request_row_view,parent,false);
              viewHolder = new RequestHolder(v2);
              break;
          default:
              View v3 = inflater.inflate(R.layout.pdf_row_view,parent,false);
              viewHolder = new PdfHolder(v3);
      }
      return viewHolder;
  }
  
  @Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
      if(holder.getItemViewType() == PDF)
      {
  
          PdfItemHolder pdfItemHolder = (PdfItemHolder) list.get(position);
          PdfHolder pdfHolder = (PdfHolder) holder;
          if(!TextUtils.isEmpty(pdfItemHolder.getPdfName())) {
              pdfHolder.pdfName.setText(pdfItemHolder.getPdfName());
              pdfHolder.pdfDescription.setText(pdfItemHolder.getPdfDescription());
              pdfHolder.Helped.setText(pdfItemHolder.getHelped());
              pdfHolder.uploadedBy.setText(pdfItemHolder.getUplodedBy());
              pdfHolder.downloadPdf.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      Toast.makeText(context, "downloading pdf bitch", Toast.LENGTH_LONG).show();
                  }
              });
              pdfHolder.container.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      onClickListener.OnItemClick(v, position);
                  }
              });
          }
          else
          {
              Toast.makeText(context,"empty",Toast.LENGTH_LONG).show();
              Log.e("empty","empty");
              pdfHolder.container.setVisibility(View.GONE);
              pdfHolder.pdfName.setVisibility(View.GONE);
              pdfHolder.pdfDescription.setVisibility(View.GONE);
              pdfHolder.Helped.setVisibility(View.GONE);
              pdfHolder.downloadPdf.setVisibility(View.GONE);
              pdfHolder.uploadedBy.setVisibility(View.GONE);
              pdfHolder.viewPdf.setVisibility(View.GONE);
          }
      }
      else
      {
          RequestHolder requestHolder = (RequestHolder) holder;
          RequestPojo requestPojo = (RequestPojo) list.get(position);
          requestHolder.name.setText(requestPojo.getName());
          requestHolder.request.setText(requestPojo.getRequest());
  
      }
  }
  
  @Override
  public int getItemCount() {
      return list.size();
  }
  @Override
  public int getItemViewType(int position)
  {
      if(list.get(position) instanceof PdfItemHolder)
          return PDF;
      else if(list.get(position) instanceof RequestPojo)
          return REQUEST
          ;
      return -1;
  }
  }
  </code></pre>
  
  <p>also I checked stack overflow to remove spaces and I added some code to adapter to check wheather the data is empty or not, it didn't worked well.
  following Is code of row views`group_row_view code
        
      
      
          </p>
  
  <pre><code>        &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:text="Requested By : "
              android:id="@+id/textView7" /&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:text="Name"
              android:id="@+id/requested_name"
              android:layout_alignParentTop="true"
              android:layout_toRightOf="@+id/textView7"
              android:layout_toEndOf="@+id/textView7" /&gt;
          &lt;View
              android:layout_width="fill_parent"
              android:layout_height="2dp"
              android:background="#c0c0c0"
  
              android:id="@+id/view1"
              android:layout_below="@+id/textView7"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true" /&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:text="Medium Text"
              android:id="@+id/request"
              android:lines="2"
              android:layout_below="@+id/view1"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true"/&gt;
      &lt;/RelativeLayout&gt;
      &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p>code of Pdf_row_view</p>
  
  <pre><code> &lt;/LinearLayout&gt;`
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  xmlns:card_view="http://schemas.android.com/apk/res-auto"&gt;
  &lt;android.support.v7.widget.CardView
      android:id="@+id/card_view_pdf_row"
      android:layout_gravity="center"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_margin="5dp"
      card_view:cardCornerRadius="3dp"
      card_view:contentPadding="2dp"&gt;
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;TextView
              android:layout_width="250dp"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:text="pdfName"
              android:id="@+id/pdf_name"
              android:layout_alignParentTop="true"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true"
  
              android:textSize="25dp"
              android:lines="1" /&gt;
          &lt;TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceSmall"
              android:text="pdf descriptionl"
              android:id="@+id/pdf_description"
              android:layout_below="@+id/pdf_name"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true"
              android:lines="2" /&gt;
  
          &lt;Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="View Pdf"
              android:id="@+id/view_pdf"
              android:layout_alignTop="@+id/download_pdf"
              android:layout_toRightOf="@+id/pdf_info_uplodedby"
              android:layout_toEndOf="@+id/pdf_info_uplodedby" /&gt;
          &lt;Button
              style="?android:attr/buttonStyleSmall"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Download Pdf"
              android:id="@+id/download_pdf"
              android:layout_alignParentRight="true"
              android:layout_alignParentEnd="true"
              android:layout_below="@+id/pdf_description" /&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceSmall"
              android:text="helped"
              android:id="@+id/helped"
              android:textSize="15dp"
              android:layout_alignBottom="@+id/view_pdf"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true" /&gt;
          &lt;View
              android:layout_width="fill_parent"
              android:layout_height="2dp"
              android:background="#c0c0c0"
              android:layout_alignTop="@+id/view_pdf"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true"
              android:id="@+id/view" /&gt;
          &lt;View
              android:layout_width="fill_parent"
              android:layout_height="2dp"
              android:background="#c0c0c0"
  
              android:id="@+id/view1"
              android:layout_below="@+id/view_pdf"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true" /&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:text="Upladed by : "
              android:id="@+id/pdf_info_uplodedby"
              android:layout_below="@+id/view_pdf"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true" /&gt;
      &lt;/RelativeLayout&gt;
  
  
      &lt;/android.support.v7.widget.CardView&gt;
  
   &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>please help me.. thank you</p>