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
How to fix the deprecation warning for the below?
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new AllItemsFragment();
case 1:
return new AvailableItemsFragment();
case 2:
return new BorrowedItemsFragment();
default:
return null;
@Override
public int getCount() {
return 3; // Three pages
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "All";
case 1:
return "Available";
case 2:
return "Borrowed";
return null;
answers here are not useful and neither is the ambiguous documentation which recommends switching to a ViewPager2 without any useful examples or indications on how to do so, just this:
Switch to androidx.viewpager2.widget.ViewPager2 and use androidx.viewpager2.adapter.FragmentStateAdapter instead.
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.