Using context in a fragment

后端 未结 30 3213
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:15

    You can use getActivity() method to get context or You can use getContext() method .

     View root = inflater.inflate(R.layout.fragment_slideshow, container, false);
        Context c = root.getContext();
    

    I hope it helps!

提交回复
热议问题