title: kotlin recyclerview data not showing
body: <p>Our question is how to show Parent and Child data from two SQLite DB tables?</p>
  
  <p>We have two tables that are added to two ArrayLists <code>childList</code> and <code>parentList</code>.</p>
  
  <p>Here are the Model Class's for each</p>
  
  <pre><code>class ModelParent {
      var idD:Int = 0
      var dept:String = ""
      var fkD:Int = 0
      var children: List&lt;ModelChild&gt; = mutableListOf()
      //var children: ArrayList&lt;ModelChild&gt;? = null
      //var children: List&lt;ModelChild&gt;  by Delegates.notNull()
      constructor (children: List&lt;ModelParent&gt;) : this()
      companion object {
         var globalVar = 1
     }
  }
  
  class ModelChild {
      var idI:Int = 0
      var item:String = ""
      var fkI:Int = 0
  }
  </code></pre>
  
  <p>We have two Adapters for each table and will post that code<br/>
  We are able to iterate through the two <code>ArrayList</code> with this code and display the data in the format we would like to show in the <code>ViewActivity</code>.</p>
  
  <pre><code>fun theGET(){
      val db = DBHelper(this)
      childList = db.queryITEM()
      parentList = db.queryDEPT()
      var PL = parentList.size
  
      do {
          var DEPT: String = parentList[z].dept
          var PARENT_LIST_FK = parentList.get(z).fkD
              println("========== Dept " + DEPT + " fkD " + PARENT_LIST_FK)
          val FK = PARENT_LIST_FK
          childList = db.queryALL(FK)
          var CL = childList.size
          for (a in 0..CL - 1) {
              var CHILD_ITEM = childList[a].item
              var CHILD_LIST_FK = childList[a].fkI
              println("========== item " + CHILD_ITEM+" fkI "+CHILD_LIST_FK)
          }
          z++
      }
      while (z &lt;= PL-1)
  }
  </code></pre>
  
  <p>We will post the <code>View Activity</code></p>
  
  <pre><code>class ViewActivity : AppCompatActivity() {
      lateinit var recyclerView: RecyclerView
  
      private var parentList:List&lt;ModelParent&gt; = ArrayList()
      private var childList:List&lt;ModelChild&gt; = ArrayList()
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_view)
  
          initRecycler()
  
      }// end onCreate
  
      private fun initRecycler() {
          val db = DBHelper(this)
          childList = db.queryITEM()
          parentList = db.queryDEPT()
  
          recyclerView = rv_parent
  
          recyclerView.apply{
              layoutManager = LinearLayoutManager(this@ViewActivity, LinearLayout.VERTICAL, false)
              adapter = ViewAdapter(parentList)
              adapter = ViewChildAdapter(children = childList)
          }
      }
  }
  </code></pre>
  
  <p><code>ViewActivity</code> has this XML file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".ViewActivity"&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/rv_parent"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>The Two Adapters and coresponding XML files</p>
  
  <pre><code>class ViewAdapter(private val parents:List&lt;ModelParent&gt;):RecyclerView.Adapter&lt;ViewAdapter.ViewHolder&gt;() {
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
          val view = LayoutInflater.from(parent.context).inflate(R.layout.the_view,parent,false)
          return ViewHolder(view)
      }
  
      override fun getItemCount(): Int {
          return parents.size
      }
  
      override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          val parent = parents[position]
          holder.textView.text = parent.dept
          holder.recyclerView.apply {
              layoutManager = LinearLayoutManager(holder.recyclerView.context, LinearLayout.VERTICAL, false) as RecyclerView.LayoutManager?
              adapter = ViewChildAdapter(parent.children!!)
          }
      }
  
      inner class ViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView){
          val recyclerView : RecyclerView = itemView.rv_child
          val textView: TextView = itemView.textView
      }
  }
  </code></pre>
  
  
  
  <pre><code>class ViewChildAdapter(private val children:List&lt;ModelChild&gt;):RecyclerView.Adapter&lt;ViewChildAdapter.ViewHolder&gt;() {
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
          val view = LayoutInflater.from(parent.context).inflate(R.layout.child_recycler,parent,false)
          return ViewHolder(view)
      }
      override fun getItemCount(): Int {
          return children.size
      }
      override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          val child = children[position]
          holder.textView.text = child.item
      }
  
      inner class ViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView){
          val textView : TextView = itemView.child_textView
      }
  }
  </code></pre>
  
  <p>Inflated XML files</p>
  
  <pre><code>&lt;android.support.v7.widget.CardView 
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:card_view="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/card_view"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:layout_margin="2dp"
      card_view:cardBackgroundColor="#fff"
      card_view:cardCornerRadius="5dp"
      card_view:cardElevation="4dp"
      card_view:cardUseCompatPadding="true"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"&gt;
  
          &lt;TextView
              android:id="@+id/textView"
              style="@style/Base.TextAppearance.AppCompat.Subhead"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignStart="@+id/rv_child"
              android:layout_alignParentTop="true"
              android:padding="20dp"
              android:background="@color/color_super_lightGray"
              android:text="Dept Header"
              android:textColor="@color/color_Purple"
              android:textSize="24sp"
              android:textStyle="bold" /&gt;
  
          &lt;android.support.v7.widget.RecyclerView
              android:id="@+id/rv_child"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentStart="true"
              android:layout_alignParentTop="true"
              android:layout_alignParentBottom="true"
              android:layout_marginTop="70dp"
              android:layout_marginBottom="0dp"
              android:orientation="horizontal"
              android:paddingLeft="4dp"
              android:paddingTop="8dp"
              tools:layout_editor_absoluteX="74dp" /&gt;
      &lt;/RelativeLayout&gt;
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="horizontal"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
  
      &lt;TextView
          android:id="@+id/child_textView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentStart="true"
          android:layout_alignParentTop="true"
          android:layout_marginStart="32dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="8dp"
          android:background="@color/color_Transparent"
          android:padding="10dp"
          android:text="TextView"
          android:textColor="@color/color_Black"
          android:textSize="20sp"
          android:textStyle="bold"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.0"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.0" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>When the <code>ViewActivity</code> is loaded ONLY the childList is displayed.</p>
  
  <p>We have tried various changes and can not display the <code>parent List</code> though using <code>theGET</code> fun the <code>parentList</code> data is displayed so we know it is in the list.</p>
  
  <p>We can run the fun <code>theGET</code> and crate a new <code>ArrayList</code> that seems futile.</p>
  
  <p>Our concern is that the <code>parentList</code> is displayed and then removed when the <code>childList</code> is displayed.</p>
  
  <p>We do not know how to prove this.</p>
  
  <p>So our question is how to show Parent and Child data in a organized fashion in the <code>View Activity</code>?</p>
  
  <p>We are adding <strong>New CODE</strong> based on @Cruces answer<br/>
  Some issues with this code are beyond out understanding<br/>
  1. We have no way to run the fun join to create the newList<br/>
  2. Parent and Child ViewHolder can be called only with receiver of containing Class<br/>
  3. Too many inner Class's and do we need an Outer Nested annotation?<br/>
  4. <code>or if both parent and child implement an interface a List&lt; IItem &gt; )</code><br/>
  We do not know how to write an interface and connect it to the JoinAdapter<br/></p>
  
  <p>While the answer poses new question we feel it better to ask with in this context = Context HUMOR
  Here is the FIX for the JoinAdapter</p>
  
  <pre><code>class JoinAdapter(internal var context: Context, val parents: List&lt;ModelParent&gt;) : RecyclerView.Adapter&lt;JoinAdapter.MyViewHolder&gt;() {
  val items = mutableListOf&lt;Any&gt;()
  
  init {
      parents //parents should be passed as a constructor argument
              .forEach {
                  items.add(it)
                  items.addAll(it.children)
              }
  }
  
  override fun getItemCount(): Int = items.size;
  
  
  fun getItem(position: Int): Any = items[position]
  
  override fun getItemViewType(position: Int): Int = if (getItem(position) is ModelParent) 0 else 1
  
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
      var view: View? = null
      if (viewType == 0) {
          view = LayoutInflater.from(parent.context).inflate(R.layout.the_view, parent, false)
          return ParentViewHolder(view!!)
      } else {
          view = LayoutInflater.from(parent.context).inflate(R.layout.child_recycler, parent, false)
          return ChildViewHolder(view!!)
      }
  }
  
  override fun onBindViewHolder(holder: MyViewHolder, position: Int) = holder.bindData(position, getItem(position))
  
  inner abstract class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
      abstract fun bindData(position: Int, item: Any)
  
  }
  
  inner class ParentViewHolder(view: View) : MyViewHolder(view) {
      override fun bindData(position: Int, item: Any) {
          val parent = item as? ModelParent ?: return
          parent.dept
          parent.fkD
          parent.children
          //bind the data here
      }
  
      init {
          val textView: TextView = view.textView
          var editCLICK: RelativeLayout = view.findViewById(R.id.editCLICK) as RelativeLayout
          //do the view setup here
      }
  
  }
  
  inner class ChildViewHolder(view: View) : MyViewHolder(view) {
      init {
          val textView : TextView = itemView.child_textView
          //do the view setup here
      }
  
      override fun bindData(position: Int, item: Any) {
          val child = item as? ModelChild ?: return
          child.item
          child.idI
          //bind the data here
      }
  }
  </code></pre>
  
  <p><strong>I am going to post the View Activity call to Join Adapter<br/></strong>
  Code does not FAIL it just shows nothing?<br/></p>
  
  <pre><code>        RecyclerAdapter1 = JoinAdapter(parents = ArrayList(),context = applicationContext)
      (recyclerView as RecyclerView).adapter = RecyclerAdapter1
  </code></pre>
  
  <p>Here is the <code>ViewJoinActivity</code> it will load the Parent Data NO Child Data<br/></p>
  
  <pre><code>class ViewJoinActivity : AppCompatActivity() {
  
  lateinit var recyclerView: RecyclerView
  private var RecyclerAdapter: JoinAdapter? = null
  private var linearLayoutManager: LinearLayoutManager? = null
  private val db = DBHelper(this)
  private var parentList:List&lt;ModelParent&gt; = ArrayList()
  private var childList:List&lt;ModelChild&gt; = ArrayList()
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_view_join)
      initRecycler()
  
  }// end onCreate
  
  override fun onResume() {
      super.onResume()
      initDB()
  }
  
  private fun initDB() {
      parentList = db.queryDEPT()
      //childList = db.queryCHILD(1)
      childList = db.queryITEM()
      // queryCHILD only selects records with a fkI equal to idD
      // SEE THE ModelChild and ModelParent
      if(parentList.isEmpty()){
          title = "No Records in DB"
      }else{
          title = "Parent List"
      }
  
          RecyclerAdapter = JoinAdapter(parents = parentList, context = applicationContext)
          (recyclerView as RecyclerView).adapter = RecyclerAdapter
      }
  
  private fun initRecycler() {
      val db = DBHelper(this)
      childList = db.queryITEM()
      parentList = db.queryDEPT()
  
      //recyclerView = rv_parent
  
      /*var PL = parentList.size
      newList.clear()
      do {
          var DEPT: String = parentList[z].dept
          var ND:String = DEPT
          var PARENT_LIST_FK = parentList.get(z).fkD
          var PL_ST = ND+" "+PARENT_LIST_FK
          newList.add(PL_ST)
  
          println("========== Dept " + DEPT + " fkD " + PARENT_LIST_FK)
          val FK = PARENT_LIST_FK
  
          childList = db.queryCHILD(FK)
          var CL = childList.size
  
          for (a in 0..CL - 1) {
              var CHILD_ITEM = childList[a].item
              var NI:String = childList[a].item
              var CHILD_LIST_FK = childList[a].fkI
              var IL_ST = NI+" "+CHILD_LIST_FK
              newList.add(IL_ST)
              println("========== item " + CHILD_ITEM+" fkI "+CHILD_LIST_FK)
          }
          z++
  
          g++
      }
      while (z &lt;= PL-1)
  
  
      var ui = newList.size
      g=0
      for(g in 0..ui-1){
          var N2 = newList[g]
  
          if(N2.toString().contains("1")){
              println("********************** We Found "+N2)
  
          }
          println("############### BOTH = "+N2)
  
      }*/
  
      recyclerView = this.findViewById(R.id.rv_parent)
      RecyclerAdapter = JoinAdapter(parents = parentList, context = applicationContext)
      linearLayoutManager = LinearLayoutManager(applicationContext)
      (recyclerView as RecyclerView).layoutManager = linearLayoutManager!!
  
      //recyclerView.apply {
          //layoutManager = LinearLayoutManager(this@ViewJoinActivity, LinearLayout.VERTICAL, false)
          //adapter = JoinAdapter(children = childList)
      //}
  
  }
  
  }
  </code></pre>
  
  <p>Calling the Join Adapter from a Activity is the issue? ?
  This Activity has a XML associated file with a RecyclerView rv_parent </p>