Question: How to get current View of a ViewPager FragmentStatePagerAdapter?
FragmentStatePagerAdapter
is required, not PagerAdapter
.
instantiateItem(View container, int position)
. This is for PagerAdapter.FragmentStatePagerAdapter
the instantiateItem has a ViewGroup param not View param: instantiateItem(**ViewGroup** container, int position)
So I hope it's not impossible, is it? Please help!
You can use the setTag trick with the view you are returning in your instantiateItem method.
Here, I'm using a ViewPager with PagerAdapter, but I think this idea might work for you too.
So, when you are instantiating your views (in PagerAdapter the method is also instantiateItem(ViewGroup container, int position)), you should use setTag to your view.
Like this:
view.setTag("view" + position);
return view;
So, when you need the current view, you should do this: View view = (View) pager.findViewWithTag("view" + pager.getCurrentItem());
, where pager is the ViewPager, which you can get passing it by params from your Activity to your adapter.
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