RecyclerView Issues
onCreateViewHolder Not Triggered
Android Development
RecyclerView Troubleshooting
Adapter Problems

Recyclerview not call onCreateViewHolder

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

onCreateViewHolder is only called when RecyclerView actually needs a new row view. If it never fires, the problem is usually not the method itself but one of the prerequisites around the adapter, layout manager, item count, or view size. The fastest way to debug it is to check those prerequisites in order instead of guessing.

What Triggers onCreateViewHolder

RecyclerView calls onCreateViewHolder when it needs a new ViewHolder instance for a visible row. That means all of the following must be true:

  • the RecyclerView has a LayoutManager
  • the adapter is attached
  • 'getItemCount() is greater than zero'
  • the RecyclerView has enough size to lay out visible children

If any of those conditions fail, onCreateViewHolder may never run.

Start With a Minimal Working Setup

Here is a small working example in Kotlin:

kotlin
1class NameAdapter(
2    private val items: List<String>
3) : RecyclerView.Adapter<NameAdapter.NameViewHolder>() {
4
5    class NameViewHolder(view: View) : RecyclerView.ViewHolder(view) {
6        val text: TextView = view.findViewById(R.id.nameText)
7    }
8
9    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NameViewHolder {
10        val view = LayoutInflater.from(parent.context)
11            .inflate(R.layout.row_name, parent, false)
12        return NameViewHolder(view)
13    }
14
15    override fun onBindViewHolder(holder: NameViewHolder, position: Int) {
16        holder.text.text = items[position]
17    }
18
19    override fun getItemCount(): Int = items.size
20}

And in an activity or fragment:

kotlin
val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = NameAdapter(listOf("Ada", "Grace", "Linus"))

If your code differs materially from that shape, start there.

Check getItemCount() First

If getItemCount() returns zero, there are no items to display, so RecyclerView has no reason to create any holders.

kotlin
1override fun getItemCount(): Int {
2    Log.d("Adapter", "count = ${items.size}")
3    return items.size
4}

This sounds obvious, but many cases come from loading data asynchronously and attaching an adapter before the list is populated. If the list changes later, call the appropriate notify method.

kotlin
items = loadedItems
notifyDataSetChanged()

If you never notify the adapter after the data arrives, RecyclerView may still think there are zero rows.

Make Sure a LayoutManager Is Set

RecyclerView does not lay out child views on its own. Without a LayoutManager, nothing is measured or displayed.

kotlin
recyclerView.layoutManager = LinearLayoutManager(requireContext())

This is one of the most common causes of "adapter methods are not being called" bugs. If onCreateViewHolder is missing, verify the layout manager before checking anything more exotic.

Confirm the View Has Size on Screen

Even with a correct adapter and nonzero item count, a RecyclerView that measures to zero height or width may not request any children.

Example XML:

xml
1<androidx.recyclerview.widget.RecyclerView
2    android:id="@+id/recyclerView"
3    android:layout_width="match_parent"
4    android:layout_height="match_parent" />

If the view is inside a parent with bad constraints, hidden visibility, or zero size, onCreateViewHolder may not run because there is no visible area to fill.

Understand That Reuse Changes Call Frequency

Another source of confusion is expecting onCreateViewHolder to fire for every row every time. That is not how RecyclerView works. Once enough holders exist for the visible screen, scrolling usually reuses them through onBindViewHolder.

So if onCreateViewHolder fired only a few times, that can be completely normal. The real question is whether it never fires at all.

Fragment and Timing Issues

In fragments, adapter setup often happens before the view hierarchy is ready or after data arrives asynchronously. A safe pattern is:

kotlin
1override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
2    val recyclerView = view.findViewById<RecyclerView>(R.id.recyclerView)
3    recyclerView.layoutManager = LinearLayoutManager(requireContext())
4    recyclerView.adapter = adapter
5}

Then update the adapter when data loading completes. If you replace the list inside the adapter, make sure the adapter sees the new data and receives the correct notify call.

Common Pitfalls

The most common cause is getItemCount() returning zero. Another is forgetting to set a LayoutManager, which prevents layout entirely. Developers also attach the adapter but never notify it when asynchronous data arrives. Zero-size or hidden RecyclerView layouts can produce the same symptom. Finally, some people expect onCreateViewHolder to run for every bind, but after the first few visible rows, RecyclerView mostly reuses holders and calls onBindViewHolder instead.

Summary

  • 'onCreateViewHolder runs only when RecyclerView needs a new visible row view.'
  • Verify LayoutManager, adapter attachment, nonzero item count, and actual view size.
  • Check getItemCount() early when debugging.
  • Notify the adapter after asynchronous data updates.
  • Do not expect onCreateViewHolder to run for every row on every scroll.
  • Start from a minimal known-good setup if the lifecycle seems stuck.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.