getSupportFragmentManager() is undefined

后端 未结 8 1258
生来不讨喜
生来不讨喜 2020-12-29 00:50

I\'m getting the following error: \"The method getSupportFragmentManager() is undefined for the type new View.OnClickListener(){}\" in my fragment

8条回答
  •  情歌与酒
    2020-12-29 01:43

    There is a problem in your project because you are using the actionBarSherlock which is deprecated... You should take a look at Android Support and use it because the supportFragmentManager is available with it. It's pretty easy to use it, add it in your build.gradle

    compile "com.android.support:support-core-utils:25.2.0"
    

    After just extends your activities and fragment with FragmentActivity or Fragment from support. Maybe you will have to make some change because of using sherlock bar

    Another thing about your problem is that you called supportFragmentManager from a fragment... you should called

    getChildFragmentManager() // because it will be a nested fragment
    

    Hope it's helpful

提交回复
热议问题