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
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import java.util.ArrayList;
import java.util.List;
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> fragmentList = new ArrayList<>();
private final List<String> fragmentListTitles = new ArrayList<>();
ViewPagerAdapter(FragmentManager fm) {
super(fm);
@NonNull
@Override
public Fragment getItem(int i) {
return fragmentList.get(i);
@Override
public int getCount() {
return fragmentListTitles.size();
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return fragmentListTitles.get(position);
void addFragment(Fragment fragment, String title){
fragmentList.add(fragment);
fragmentListTitles.add(title);
I found a possible solution here:
FragmentPagerAdapter deprecated
But it's in Kotlin.
The warning is on the word:
super
//Here
super(fm);
This constructor is deprecated.
use FragmentPagerAdapter(FragmentManager, int) with BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
So replace super(fm) with:
super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
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.