添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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.

    Md. Kabir Hassan - Welcome back to Stack Overflow. It looks like it's been a while since you've posted and may not be aware of the current policies since most or all seven of your recent answers appear likely to have been entirely or partially written by AI (e.g., ChatGPT). Please be aware that posting of AI-generated content is banned here. If you used an AI tool to assist with any answer, I would encourage you to delete it. We do hope you'll stick around and continue to be a valuable part of our community by posting your own quality content. Thanks! – NotTheDr01ds Jul 12 at 22:03 Readers should review this answer carefully and critically, as AI-generated information often contains fundamental errors and misinformation. If you observe quality issues and/or have reason to believe that this answer was generated by AI, please leave feedback accordingly. The moderation team can use your help to identify quality issues. – NotTheDr01ds Jul 12 at 22:03

    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.

  •