Skip to content

Model and list do not match when converting from java to kotlin

Whatever a video is made on Youtube, I do the same, Java language is used in the video, and I try to do it with Kotlin. I do exactly the same. I tried all the situations but could not fix them. I would be glad if you help

var photoList: List<Photo>? = null
photoList = ArrayList()
photoList = ArrayList(Arrays.asList(demoModel!!.photos))

data class DemoModel(
    var photos: List<Photo>? = null

class Adapter(private val context: Context, private val photoList: List<Photo>) :
    RecyclerView.Adapter<Adapter.MyViewHolder>() {

enter image description here


This is how I fixed it, but this time only the last value appears in the recyclerView @aldrin

//In call;
val demoModel = response.body()
                demoModel?.let {

//In recyclerView function;
fun PutDataIntoRecyclerView(photoList: List<List<Photo>?>) {
        val adapter = Adapter(this, photoList)
        binding.recyclerViewID.adapter = adapter

//In Adapter
class Adapter(private val context: Context, private val photoList: List<List<Photo>?>) :
    RecyclerView.Adapter<Adapter.MyViewHolder>() {
//In Adapter onBindViewHolder;
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val myList = photoList[position]
        myList?.forEach {
            holder.photoId?.text =
            holder.photoSol?.text = it.sol.toString()
            holder.photoEarthDate?.text = it.earthDate.toString()