I would like to know is it possible to use the class FragmentStatePagerAdapter or its equivalent without the support library?
I know how to use native fragments in place of those from the support library and many other classes have their similar equivalents, but I can't find what should be used instead of this class.
I basically want to extend it for using it in my adapter like this
public class ImageAdapter extends FragmentStatePagerAdapter {...
This class is deprecated. Switch to androidx. viewpager2. widget.
To use ViewPager and tabs, you need to add a dependency on ViewPager and on Material Components to your project. To insert child views that represent each page, you need to hook this layout to a PagerAdapter .
If you have fragment tag though, you can easily retrieve reference to it from the FragmentManager by calling findFragmentByTag() .
I presume you've read the ViewPager
docs, but just in case:
This class is currently under early design and development. The API will likely change in later updates of the compatibility library, requiring changes to the source code of apps when they are compiled against the newer version.
I too was initially baffled as to why the PagerAdapter classes were not a part of the android.app.*
namespace. As they are still undergoing refinement, they have been included in the support libraries so that those libraries can be updated frequently as changes are introduced (AOSP updates are far less convenient and thus occur on a far less frequent basis). It seems that once the Android team gives final shape to the ViewPager
and all its related classes, they will become a part of the AOSP. Even the ViewPager
class itself is still a part of the V4 support library. So what you want should be possible in the near future ... :)
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