Я попытался запустить ваш код и он работает нормально.
package com.example.demo.ui.main
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.demo.R
import kotlinx.android.synthetic.main.list_item_crime.view.*
import kotlinx.android.synthetic.main.main_fragment.*
class CrimeListFragment : Fragment() {
private lateinit var cadapter: CrimeAdapter
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.main_fragment, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setAdapter()
}
private fun setAdapter() {
cadapter = CrimeAdapter(getCrimeList())
with(recycler) {
adapter = cadapter
layoutManager = androidx.recyclerview.widget.LinearLayoutManager(
context,
RecyclerView.VERTICAL,
false
)
}
}
private fun getCrimeList(): List<Crime> {
val list = mutableListOf<Crime>()
list.add(Crime("Test", "Today"))
list.add(Crime("Test", "Today"))
list.add(Crime("Test", "Today"))
list.add(Crime("TESt", "Today"))
return list
}
private class CrimeAdapter(var crimes:List<Crime>): RecyclerView.Adapter<CrimeAdapter.crimeViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType:Int):crimeViewHolder{
return crimeViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.list_item_crime,
parent,
false
)
)
}
override fun getItemCount():Int{
return crimes.size
}
override fun onBindViewHolder(holder:crimeViewHolder,position:Int){
val crime=crimes[position]
holder.itemView.apply{
crime_title.text = crime.title
crime_date.text = crime.date
}
}
inner class crimeViewHolder(itemView: View):RecyclerView.ViewHolder(itemView) {}
}
}
макет фрагмента
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.CrimeListFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:listitem="@layout/list_item_crime"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
list_item_crime такой же, как ваш