Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Android Studio says fragment pager adapter is deprecated.
How can I remove this error?
here is the screenshot
public static class ViewPagerAdapter extends FragmentPagerAdapter {
private ArrayList<Fragment> fragments;
private ArrayList<String> titles;
public ViewPagerAdapter(@NonNull FragmentManager fm) {
super(fm);
The FragmentPagerAdapter class in Android is indeed deprecated as of AndroidX library version 1.2.0. It is recommended to use FragmentStatePagerAdapter or FragmentPagerAdapter2 instead.
Replace FragmentPagerAdapter with FragmentStatePagerAdapter:
public static class ViewPagerAdapter extends FragmentStatePagerAdapter {
Update the constructor of ViewPagerAdapter to call the appropriate
superclass constructor:
public ViewPagerAdapter(@NonNull FragmentManager fm) {
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
These changes will ensure that you are using the recommended replacement for FragmentPagerAdapter and resolve the deprecation problem.
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.