Using context in a fragment

后端 未结 30 2612
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:37

    You can call getActivity() or,

    public void onAttach(Context context) {
        super.onAttach(context);
        this.activity = (CashActivity) context;
        this.money = this.activity.money;
    }
    

提交回复
热议问题