title: How to implement Vertical Recyclerview inside vertical recyclerview android?
body: <p>Suppose i have <em>2 items</em> in a <code>RecyclerView</code> where each item has a <code>innerrecyclerview</code> which have around <em>100 items</em> in it both are vertical or anything that does not have any affect on the existing problem. </p>
  
  <p>I have implemented the method available here on other stackoverflow questions or other android Blogs but were not helpful.</p>
  
  <p>I have a question regarding <code>onbindviewholder</code>, the item 1 inner <code>RecyclerView</code>'s <code>onbindviewholder</code> gets called for all the elements <em>i.e. 100</em> at once and they are not recycling or anything as the <code>onbindviewholder</code> is not calling with scrolling which should get for a normal behaving <code>RecyclerView</code>. </p>
  
  <p>How to make the <code>innerrecyclerview</code> recycle as well because all other posts have not talked about this.</p>
  
  <p><strong>CourseRVAdapter or ParentAdapter</strong></p>
  
  <pre><code>public class CourseRVAdapter extends RecyclerView.Adapter&lt;CourseRVAdapter.SimpleViewHolder&gt; {
  
          private Context mContext;
          private List&lt;data&gt; merchantlist;
          private List&lt;data&gt; merchantlist2;
          private RecyclerView horizontalList;
          Typeface MRR;
          private Typeface MR;
  
  
          public class SimpleViewHolder extends RecyclerView.ViewHolder {
              public final TextView title;
              private HorizontalRVAdapter horizontalAdapter;
  
              public SimpleViewHolder(View view) {
                  super(view);
                  Context context = itemView.getContext();
                  title = (TextView) view.findViewById(R.id.text_1);
                  horizontalList = (RecyclerView) itemView.findViewById(R.id.my_recycler_view);
                  horizontalList.setLayoutManager(new CustomLinearLayoutManager(mContext, 3));
                  horizontalAdapter = new HorizontalRVAdapter(merchantlist, mContext, MR);
                  horizontalList.setAdapter(horizontalAdapter);
              }
          }
  
  
  
          CourseRVAdapter(List&lt;data&gt; merchantlist2, Context mContext, Typeface MRR, List&lt;data&gt; merchantlist, Typeface MR) {
  
              this.merchantlist2 = merchantlist2;
              this.merchantlist = merchantlist;
              this.mContext = mContext;
              this.MRR = MRR;
              this.MR = MR;
  
          }
          public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
              final View view = LayoutInflater.from(mContext).inflate(R.layout.merchant_list_header, parent, false);
              return new SimpleViewHolder(view);
          }
  
          @Override
          public void onBindViewHolder(SimpleViewHolder holder, final int position) {
  
  
  
          }
  
          @Override
          public int getItemCount() {
  
              return merchantlist2.size();
          }
  
      }
  </code></pre>
  
  <p><strong>HorizontalRVAdapter or Inneradapter</strong></p>
  
  <pre><code>public class HorizontalRVAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
  
              List&lt;data&gt; merchantlist;
              FragmentActivity main;
              Context mContext;
              Typeface MRR;
  
              public HorizontalRVAdapter(List&lt;data&gt; merchantlist, Context mContext, Typeface MRR) {
  
                  this.merchantlist = merchantlist;
                  this.mContext = mContext;
                  this.MRR = MRR;
  
              }
  
              private class ItemViewHolder extends RecyclerView.ViewHolder {
  
                  private TextView merchantname;
  
                  public ItemViewHolder(View itemView) {
                      super(itemView);
                      merchantname = (TextView) itemView.findViewById(R.id.merchant_name);
                  }
              }
  
              @Override
              public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                  Context context = parent.getContext();
                  View itemView = LayoutInflater.from(context).inflate(R.layout.merchant_list_item, parent, false);
                  ItemViewHolder holder = new ItemViewHolder(itemView);
                  return holder;
              }
  
              @Override
              public void onBindViewHolder(RecyclerView.ViewHolder rawHolder, int position) {
  
                  ItemViewHolder holder = (ItemViewHolder) rawHolder;
                  data list = merchantlist.get(position);
                  holder.merchantname.setText(list.merchantname);
                  holder.itemView.setTag(position);
  
                  Log.d("TAG", "onbindviewholder -- &gt; " + position);
              }
  
              @Override
              public int getItemCount() {
                  return merchantlist.size();
              }
  
          }
  </code></pre>
  
  <p>I have not added how i am populating the data for both the <code>recyclerview</code>.</p>
  
  <p>For instance <code>parentrecyclerview</code> has 1 or 2 items and <code>innerrecyclerview</code> has 100 items.</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>so after getting the first comment i am updating what i want to acheive to get better responses.</p>
  
  <p>I have a two textview and a Gridrecyclerview and i want the two textview to scroll when i scroll gridrecyclerview. i came up with the idea of doing this by defining header for those two text view and simple item holder for the griditems.</p>
  
  <p>Then i had to s set Gridlayoutmanager with the span but it also included the first two text and i end up with the two text view in that grid too which was unwanted.
  <a href="https://i.stack.imgur.com/t3Esi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t3Esi.png" alt="The blue one is the one item of the oarentrecyclerview and the icon and text are the item for insiderecyclerview i want them to scroll in cohesion"></a></p>