FragmentPagerAdapter Deprecated (FPAD)


FPAD:   SOLD       




Since the release of the latest version of API 27 FragmentPagerAdapter I became deprecated, it seems that the Android SDK developers are actively overhauling and improving their system. Okay, that's good, but the problem is that their socialization is lacking so we have to consult with other parties outside their platform, one of which is in this forum.

In some cases, I understand the implementation  super(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT), and am I forced to use this? I don't know the effect on my other code, and this ignorance can be fatal if I force it.

Okay, let's touch on my code overview at that time.

import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter

Previously it was no problem, but after doing the update,  FragmentPagerAdapter di class MyViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager){ its name became tarnished.

Is there any solution for this kind of deprecated case.

class MyViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager){
        private val fragmentList : MutableList<androidx.fragment.app.Fragment> = ArrayList()
        private val titleList : MutableList<String> = ArrayList()

        override fun getItem(position: Int): androidx.fragment.app.Fragment {
            return fragmentList[position]
        }

        override fun getCount(): Int {
            return fragmentList.size
        }

        fun addFragment(fragment: androidx.fragment.app.Fragment, title: String){
            fragmentList.add(fragment)
            titleList.add(title)
        }

        override fun getPageTitle(position: Int): CharSequence? {
            return titleList[position]
        }
    }

Solution

It's simple Dev, change it.

class MyViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager)

Be like this

class MyViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT)

The conclusion is that I think that MyViewPagerAdapter does not require any specific value configuration.


Post a Comment

Previous Next

نموذج الاتصال