How to call getFragmentManager on Recycler.Adapter?

前端 未结 9 2110
执笔经年
执笔经年 2020-12-23 16:22

I am converting ListView of my app to RecyclerView. On ListView, it was very easy to implement OnClickListener but in RecyclerView, we have to do it in adapter. I want to op

9条回答
  •  执念已碎
    2020-12-23 17:21

    You just need an activity context passed in your constructor. Be sure to call new Adapter(this,...) from activities and new Adapter(getActivity(),...) from fragments.

    private Context context;
    
    @Override
    public void onClick(View v) {
        FragmentManager manager = ((AppCompatActivity)context).getSupportFragmentManager();
    }
    

提交回复
热议问题