Cannot resolve method 'getSupportFragmentManager ( )' inside Fragment

后端 未结 14 723
别跟我提以往
别跟我提以往 2020-12-01 05:16

I found the message Cannot resolve method \'getSupportFragmentManager ( )\' I want to fragment as activity. because I want to use Maps on the tabs swipe.

pub         


        
相关标签:
14条回答
  • 2020-12-01 05:32

    Extends FragmentActivity instead of Activity

    0 讨论(0)
  • 2020-12-01 05:33

    If you're getting "Cannot resolve method getSupportFragmentManager()", try using

    this.getSupportFragmentManager()
    

    It works for me when dealing with DialogFragments in android

    0 讨论(0)
  • 2020-12-01 05:34

    I tried all above, but none working

    Finally tried this my own

    getBaseActivity().getFragmentManager()
    

    and is working .. :)

    0 讨论(0)
  • 2020-12-01 05:35

    As per the documentation, getSupportFragmentManager() is present only inside AppCompatActivity class. It is not present inside Activity class. So make sure your class extends AppCompatActivity class.

    public class MainActivity extends AppCompatActivity {
    }
    
    0 讨论(0)
  • 2020-12-01 05:35

    getFragmentManager()

    just try this.it worked for my case

    0 讨论(0)
  • 2020-12-01 05:36

    Also you can use AppCompatActivity instead of Activity.
    Then getSupportFragmentManager() will work.
    And also not forget to make your App theme extend AppCompat theme in this case

    0 讨论(0)
提交回复
热议问题