I recently updated from support library recyclerview-v7:23.1.1 to recyclerview-v7:25.1.0.
My Layout contains 2 recylerviews splitted 50% on the screen. The xml code is as follows:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbars="none"/>
<android.support.v4.widget.Space
android:layout_width="@dimen/two_dp"
android:layout_height="match_parent"
android:background="@color/dark_gray"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbars="none"/>
</LinearLayout>
Now onBindViewHolder is called for all list items instead of only the visible items. This started happening after update to support library 25.1.0.
It is working fine if weights are removed, but having 2 recylcerviews side by side is required.
How do I tell recyclerview to recycle views instead of loading all?
UPDATE: It works fine on Marshmallow and above devices. The issue is present in Lollipop or below. You can find a demo project here: https://bitbucket.org/aniketit/recyclerviewtest
However, in RecyclerView the onBindViewHolder gets called every time the ViewHolder is bound and the setOnClickListener will be triggered too. Therefore, setting a click listener in onCreateViewHolder which invokes only when a ViewHolder gets created is preferable.
By default it have 5. you can increase as per your need. Save this answer.
onBindViewHolder. Called by RecyclerView to display the data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.
I ran into the same issue which persisted after removing weighted and 0dp elements. In my case, the issue was rather trivial - I had inadvertently put my RecyclerView inside of a NestedScrollView with fillViewPort=true. This causes the Adapter will build all the elements for the view and you will notice a significant delay in responsiveness.
Turns out the issue will occur if you just have the RecyclerView in a plain old ScrollView too.
I had the same issue. RecyclerView was recycling well in Marshmallow but not before.
My mistake was to put my RecyclerView into a ScrollView. You should check if you have a scrollview, if yes, remove it and your issue will be solved for pre marshmallow devices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With