Using context in a fragment

后端 未结 30 2650
Happy的楠姐
Happy的楠姐 2020-11-22 00:05

How can I get the context in a fragment?

I need to use my database whose constructor takes in the context, but getApplicationContext() and Fragmen

30条回答
  •  遇见更好的自我
    2020-11-22 00:29

    getContext() came in API 23. Replace it with getActivity() everywhere in the code.

    See if it fixes the error. Try to use methods which are in between the target and minimun API level, else this error will come in place.

提交回复
热议问题