Error: required: android:support.v4.FragmentManager, found: android.app.FragmentManager

前端 未结 4 532
无人及你
无人及你 2021-01-22 12:47
 FragmentManager manager = getFragmentManager();

It is giving the error

required : android:support.v4.FragmentManager
foun

4条回答
  •  臣服心动
    2021-01-22 13:38

    This solved the problem for me for creating fragment with viewpager.

    Make your activity extend AppCompatActivity(), then use supportFragmentManager.

    abstract class YourActivity() : AppCompatActivity() { /*your Activity Code*/ }
    

    Then, when creating your viewpager with fragment:

     val adapter = ViewPagerAdapter(supportFragmentManager)
     viewPager.adapter = adapter
     sliding_tabs.setupWithViewPager(viewPager)
    

提交回复
热议问题