Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FragmentStatePagerAdapter WITHOUT support library

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 {...
like image 665
Igor Čordaš Avatar asked Aug 29 '13 13:08

Igor Čordaš


People also ask

What can I use instead of Fragmentpageradapter?

This class is deprecated. Switch to androidx. viewpager2. widget.

How to add ViewPager in android?

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 .

How do I get fragments from Fragmentstateadapter?

If you have fragment tag though, you can easily retrieve reference to it from the FragmentManager by calling findFragmentByTag() .


1 Answers

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 ... :)

like image 58
Y.S Avatar answered Oct 14 '22 02:10

Y.S