Android getActivity() is undefined

前端 未结 4 559
别跟我提以往
别跟我提以往 2020-12-15 03:52

I have errors in my class MainActivity.

The error: The method getActivity() is undefined for the type MainActivity

publ         


        
相关标签:
4条回答
  • 2020-12-15 04:35

    You want getActivity() inside your class. It's better to use

    yourclassname.this.getActivity()
    

    Try this. It's helpful for you.

    0 讨论(0)
  • 2020-12-15 04:36

    If you want to call your activity, just use this . You use the getActivity method when you are inside a fragment.

    0 讨论(0)
  • 2020-12-15 04:40

    This is because you're using getActivity() inside an inner class. Try using:

    SherlockFragmentActivity.this.getActivity()

    instead, though there's really no need for the getActivity() part. In your case, SherlockFragmentActivity .this should suffice.

    0 讨论(0)
  • 2020-12-15 04:51

    In my application, it was enough to use:

    myclassname.this

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