How to call getFragmentManager on Recycler.Adapter?

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();
}

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();

To add on to the approved answer: if you still get an error you might need to replace this line;

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

With this

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

For me this was because I was using the support.v4.app.FragmentManager instead of the regular fragmentmanager

Still get an error?

As one comment below pointed out, this might throw a java.lang.ClassCastException: and log ... cannot be cast to android.support.v7.app.AppCompatActivity (check comments for details)

Their fix was to use this instead (I haven't tested it but it worked for them):

((AppCompatActivity)activity).getSupportFragmentManager()