RecyclerView.onBindViewHolder called only once RecyclerView.onBindViewHolder called only once android android

RecyclerView.onBindViewHolder called only once


The problem is not in your code. Make sure you set layout_height to wrap_content of RecyclerView child item.


Take care of the onBindViewHolder behaviour in the RecyclerView cycles. RecyclerView.ViewHolder position 0 itemView

android:layout_height="match_parent"

occupies the current displayed screen. Scroll and onBindViewHolder should be triggered but make sure getItemCount was set appropriately.

Solution:

android:layout_height="wrap_content"

Solution with ConstraintLayout as inflated itemView:

<?xml version="1.0" encoding="utf-8"?>    <android.support.constraint.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:layout_width="match_parent"    android:layout_height="wrap_content"><!-- IMPORTANT -->    <!-- ... --></android.support.constraint.ConstraintLayout>


In a case I came across, was when my recyclerview was scrollable only horizontally, not vertically.