This is the use case:
I have a recyclerview list of 5 food stuff imageviews:
- Watermelon
- Mango
- Peach
- Apple
- Guava
I want to log an output (Log.e(TAG, "Peach shown!")
when the peach imageview is fully visiile in the recyclerview when the user scroll past it.
Is there a callback that is called when a view is fully visible in the recyclerview? I almost want to turn the method findFirstCompletelyVisibleItemPosition ()
into a callback method: http://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html#findFirstCompletelyVisibleItemPosition()
I read this thread:
RecyclerView - callback when view is no longer visible and looked at the docs here http://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnChildAttachStateChangeListener.html but I see the callback method onChildViewAttachedToWindow()
is called when:
Called when a view is attached to the RecyclerView.
Attached can be before the view actually gets displayed.
I can think of one highly inefficient way of doing this:
Set the
RecyclerView.OnScrollListener
on your recyclerviewCall
mLinearLayoutManager.findFirstCompletelyVisibleItemPosition()
inside theonScrolled
method. Check the int that is returned to equal 3.
Each time the recyclerview scrolls, hundreds of calculations are going to be performed.