How to call getFragmentManager on Recycler.Adapter?

前端 未结 9 2116
执笔经年
执笔经年 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:11

    Make sure to pass context to the ArrayAdapter or RecyclerViewAdpater,So that we can get it inside Adapter Class.

    If your mainActivity is extending Activity then use :

     FragmentManager fragmentManager = ((Activity)context).getFragmentManager();
    

    If your mainActivity is extending AppCompatActivity then use :

    FragmentManager fragmentManager = ((AppCompatActivity)context).getSupportFragmentManager();
    

提交回复
热议问题