This is the use case:
I have a recyclerview list of 5 food stuff imageviews:
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 recyclerview
Call mLinearLayoutManager.findFirstCompletelyVisibleItemPosition() inside the onScrolled method. Check the int that is returned to equal 3.
Each time the recyclerview scrolls, hundreds of calculations are going to be performed.
You actually should handle it in the onScrolled() method, as you mentioned. The findFirstCompletelyVisibleItemPosition() method is very efficient and the calculations being made will not affect most devices, including the low-end ones.
As a side note, I think what you want is the findLastCompletelyVisibleItemPosition() method.
Been there, done that :-)
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