public class PubItemView extends RelativeLayout{ ..... public PubItemView(Context context) { this(context, null); } public PubItemView(Context context, AttributeSet attrs) { this(context, attrs, 0); } .... @OnClick(R.id.buttonReport) public void openReport() { ReportDialogFrg fr = new ReportDialogFrg(); Bundle args = new Bundle(); args.putSerializable(ReportDialogFrg.PUBLICATION_KEY, pub); fr.setArguments(args); fr.show((NearestFrg)getActivity().getFragmentManager(), null);//тут проблема } } 

If I were in a fragment then

 fr.show(getActivity().getFragmentManager(), null); //для фрагмента работает 

How to call the fr fragment from PubItemView?

  • And what a mistake? ... Context does not get? - Yuriy SPb

1 answer 1

It is necessary to get the context, connect it to the activation and get the FragmentManager out of it like this:

 fr.show(((ИМЯ_КЛАССА_АКТИВИТИ_В_КОЕМ_НАХОДИТСЯ_VIEW)getContext()).getFragmentManager(), null);