-1

I have a RecyclerView.Adapter like this:

internal class MyAdapter : RecyclerView.Adapter<MyAdapter.MyViewHolder>() {
  private val data: List<MyModel> = SeedData().seed()

  override fun onCreateViewHolder(v: ViewGroup, viewType: Int): MyViewHolder {
    val binding = MyListitemBinding.inflate(LayoutInflater.from(v.context), v, false)
    return MyViewHolder(binding)
  }

  override fun getItemCount() = data.size

  override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
    holder.bind(data[position])
  }
}

However, only the first item from the data is getting displayed (i.e. onCreateViewHolder & onBindViewHolder invoked only one time). How can I make it display all items from the data properly?

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147

1 Answers1

0

The commented answers above are correct. My list item (views) were full height of screen: enter image description here

This means that RecyclerView would only update the ViewHolder once you scroll to the next element. The solution is to modify the height of these items.

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147