, Удалите эту строку, и проблема будет решена.

опрос заключается в том, как отобразить данные Parent и Child из двух таблиц SQLite DB?

У нас есть две таблицы, которые добавляются в два ArrayListschildList а такжеparentList.

Вот модель класса для каждого

class ModelParent {
    var idD:Int = 0
    var dept:String = ""
    var fkD:Int = 0
    var children: List<ModelChild> = mutableListOf()
    //var children: ArrayList<ModelChild>? = null
    //var children: List<ModelChild>  by Delegates.notNull()
    constructor (children: List<ModelParent>) : this()
    companion object {
       var globalVar = 1
   }
}

class ModelChild {
    var idI:Int = 0
    var item:String = ""
    var fkI:Int = 0
}

У нас есть два адаптера для каждой таблицы, и мы разместим этот код
Мы можем перебрать дваArrayList с этим кодом и отображать данные в формате, который мы хотели бы показать вViewActivity.

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 <= PL-1)
}

Мы опубликуемView Activity

class ViewActivity : AppCompatActivity() {
    lateinit var recyclerView: RecyclerView

    private var parentList:List<ModelParent> = ArrayList()
    private var childList:List<ModelChild> = 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)
        }
    }
}

ViewActivity имеет этот файл XML

<?xml version="1.0" encoding="utf-8"?>
<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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>

Два адаптера и соответствующие XML-файлы

class ViewAdapter(private val parents:List<ModelParent>):RecyclerView.Adapter<ViewAdapter.ViewHolder>() {
    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
    }
}
class ViewChildAdapter(private val children:List<ModelChild>):RecyclerView.Adapter<ViewChildAdapter.ViewHolder>() {
    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
    }
}

Надутые файлы XML

<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">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <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" />

        <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" />
    </RelativeLayout>
</android.support.v7.widget.CardView>
<?xml version="1.0" encoding="utf-8"?>
<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">

    <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" />

КогдаViewActivity загружен ТОЛЬКО childList отображается.

Мы попробовали различные изменения и не можем отобразитьparent List хотя используяtheGET веселоparentList данные отображаются, поэтому мы знаем, что это в списке.

Мы можем запустить весельеtheGET и создать новыйArrayList это кажется бесполезным.

Мы обеспокоены тем, чтоparentList отображается, а затем удаляется, когдаchildList отображается.

Мы не знаем, как это доказать.

Таким образом, наш вопрос заключается в том, как организованно показывать данные о родителях и детях вView Activity?

Мы добавляемНовый КОД на основе ответа @Cruces
Некоторые проблемы с этим кодом находятся за пределами нашего понимания
1. У нас нет возможности запустить забавное объединение, чтобы создать новый список
2. Parent и Child ViewHolder могут быть вызваны только с получателем содержащего класса
3. Слишком много внутренних классов, и нужна ли нам аннотация внешнего вложенного?
4.or if both parent and child implement an interface a List< IItem > )
Мы не знаем, как написать интерфейс и подключить его к JoinAdapter

Хотя ответ ставит новый вопрос, мы считаем, что лучше задавать его в этом контексте = Контекст ЮМОР Вот ИСПРАВЛЕНИЕ для JoinAdapter

class JoinAdapter(internal var context: Context, val parents: List<ModelParent>) : RecyclerView.Adapter<JoinAdapter.MyViewHolder>() {
val items = mutableListOf<Any>()

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
    }
}

Я собираюсь опубликовать вызов View Activity для присоединения адаптера
Код не сбоит, просто ничего не показывает?

        RecyclerAdapter1 = JoinAdapter(parents = ArrayList(),context = applicationContext)
    (recyclerView as RecyclerView).adapter = RecyclerAdapter1

ЗдесьViewJoinActivity это загрузит Родительские Данные, НЕТ Дочерних Данных

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<ModelParent> = ArrayList()
private var childList:List<ModelChild> = 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 <= 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)
    //}

}

}

Вызов адаптера соединения из действия - это проблема? ? У этого действия есть XML-файл, связанный с RecyclerView rv_parent

Ответы на вопрос(3)

Ваш ответ на вопрос