Feature Request P4
Status Update
Comments
al...@gmail.com <al...@gmail.com> #2
+1
da...@gmail.com <da...@gmail.com> #3
I encounter this problem, too
ph...@gmail.com <ph...@gmail.com> #4
A common hack in ViewPager1 was to set your views tag with the position number in intantiateItem after inflating.
view.setTag( "" + position );
then later retrieve current visible view with
view = viewPager.findViewWithTag( "" + viewPager.getCurrentItem() );
This still works with ViewPager2. Set your views tag in onBindViewHolder.
But yeah, a proper method to retrieve current visible view (or an off screen view) which hides the internal implementation would be much appreciated.
view.setTag( "" + position );
then later retrieve current visible view with
view = viewPager.findViewWithTag( "" + viewPager.getCurrentItem() );
This still works with ViewPager2. Set your views tag in onBindViewHolder.
But yeah, a proper method to retrieve current visible view (or an off screen view) which hides the internal implementation would be much appreciated.
Description
It is not possible anymore to do as such, as ViewPager2 uses an internal RecyclerView, although we can access the first child of ViewPager2 which will be a RecyclerViewImpl, that feels like relying on internal implementation.
Could it be possible to expose the current findViewHolderByAdapterPosition/findViewHolderByItemId methods directly in the ViewPager2 to cleanly resolve this?