Almost every app shows a list — chats, products, feeds. RecyclerView displays large lists efficiently by recycling item views as you scroll.
The three pieces
- RecyclerView — the scrollable container in your layout.
- Adapter — binds your data list to item views.
- ViewHolder — holds the views for one row (so they're reused).
class UserAdapter(val items: List<User>) :
RecyclerView.Adapter<UserAdapter.VH>() {
class VH(val b: ItemUserBinding) : RecyclerView.ViewHolder(b.root)
override fun onCreateViewHolder(p: ViewGroup, t: Int): VH {
val b = ItemUserBinding.inflate(LayoutInflater.from(p.context), p, false)
return VH(b)
}
override fun onBindViewHolder(h: VH, pos: Int) {
h.b.name.text = items[pos].name
}
override fun getItemCount() = items.size
}
// In the Activity
binding.list.layoutManager = LinearLayoutManager(this)
binding.list.adapter = UserAdapter(users)
Tip: For lists that change, use
ListAdapter with DiffUtil — it animates only the rows that actually changed.Summary
RecyclerView + Adapter + ViewHolder is the standard pattern for performant lists. Master it once and reuse it everywhere.