title: Expandable RecyclerView: How to have different "child-rows" (which are displayed when an item is expanded) have different layouts?
body: <p>I am trying to use <a href="https://github.com/bignerdranch/expandable-recycler-view" rel="nofollow noreferrer">this library project by dgreenhalgh for creating an expandable RecyclerView</a>, <strong>but my requirement is to have an <em>expandable</em> RecyclerView <em>with different layouts for different rows</em>.</strong> </p>
  
  <p>So I first wrote a small example application to test the library project. <strong><a href="http://www.mediafire.com/download/obrdwdvh00b2cki/ExpandableRecyclerView%40GithubTestOne.rar" rel="nofollow noreferrer">I am posting it here.</a></strong> <strong>Now I need to make it use different layouts for different <em>children-rows</em></strong> - i.e. when the user clicks on an item in the list (let's call that <em>parent-row</em> for now), it is expanded to show its children-rows, like in the following screenshot.</p>
  
  <p><a href="https://i.stack.imgur.com/H45oU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H45oU.png" alt="enter image description here"></a></p>
  
  <p>But I need different layouts for different <em>child</em>-rows. I searched around and found <a href="http://doublewong.com/2014/create-recyclerview-with-multiple-view-type/" rel="nofollow noreferrer">this example for "RecyclerView with Multiple Viewtype" </a>quite simple and nice. So I want to do this like in the example, that is by extending the  ViewGroup...</p>
  
  <p><strong>In this approach</strong>, they extend a main ViewGroup with different ViewGroups (each corresponding to a layout for a row-style). Then in <code>getItemViewType</code> of the <code>RecyclerAdapter</code>, they decide what <code>viewtype</code> to return based on the <code>position</code> passed in the method, and then in <code>onCreateViewHolder</code>, decide which layout to inflate based on the <code>viewtype</code> passed.</p>
  
  <p><strong>In my use-case, it would have been straightforward if it was the <code>parent-rows</code> that I needed the multiple layouts for</strong>, because it is the data-list containing the data to show in the <code>parent-rows</code> which is passed to our <code>ExpandableRecyclerAdapter</code>. So in our <code>getItemViewType</code>, we can do something like </p>
  
  <pre><code>@Override
  public int getItemViewType ( int position ) {
      int viewType;
      if ( groups.get ( position ).getImagePath () != null ) { //****groups is the list containing the data to be displayed in the recyclerview's "parent" items
          ...
      } else {
          ...
      }
      return viewType;
  }
  </code></pre>
  
  <p>where <code>groups</code> is the <code>ArrayList</code> passed to the <code>RecyclerViewAdapter</code> which contains the data to be displayed in the parent-rows. </p>
  
  <p><strong>This <code>ArrayList</code> contains objects of type <code>ParentObject</code> (actually a class I wrote which extends <code>ParentObject</code>). Inside this class, a method by the name of <code>getChildObjectList</code> returns a <code>List&lt;ChildObject&gt;</code> which contains the data to be displayed in the child-rows.</strong> </p>
  
  <p>QUESTION:</p>
  
  <p><strong>So I can not have a <code>getItemViewType</code> and the entire functionality of the <code>RecyclerViewAdapter</code> inside my class which extends <code>ParentObject</code>, which is (creating) and returning the <code>ArrayList</code> which contains the data to be displayed in the child-rows.</strong></p>
  
  <p><strong>So how should I go about it?</strong></p>