Reputation: 21
I have following issue.
Fragment
with RecyclerView
-> navigate to next fragment -> navigate back popBackStack()
-> RecyclerView
doesn't show items
It happens every other time(adapter instance inside Fragment
always the same)
Adapter's itemCount
always return's > 0 but I've checked that no onCreateViewHolder/onBindViewHolder
method was called and
also LayoutManager
instance is present
This behavior happens on Samsung G7(don't know about other Samsung devices but everything is OK on Nexus, Xiaomi, LG)
setHasFixedSize(true)
adapter.setupData(content)
rv_test.adapter = adapter
/*setupData method*/
items.clear()
items.addAll(data)
notifyItemRangeInserted(0, data.size)
<androidx.coordinatorlayout.widget.CoordinatorLayout
...
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:clipToPadding="false"
android:focusableInTouchMode="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
android:scrollbars="none"/>
...
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Upvotes: 0
Views: 30
Reputation: 24857
You are adding data and notifying of an update before you are actually setting the adapter on the RecylerView.
Change:
adapter.setupData(content)
rv_test.adapter = adapter
To:
rv_test.adapter = adapter
adapter.setupData(content)
Upvotes: 1