How can I call a fragment from the MainActivity by pressing a button.

Fragment itself.

public class EventInterestFragment extends DialogFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.activity_event_interests, container, false); } } 

and what you need to enter here to call \ display a fragment with an XML file)

public void btn_click (View v) { Реализация по вызову фрагмента. }

And you can please implementation. Thank you in advance.

  • What does it mean to cause a fragment? Simply, if it is some kind of dialog box, then you can call the dialog and load your XML markup into it. - Nikotin N
  • @NikotinN Well, I have a Fragment and in the future I will supplement the code there and I need to, at the touch of a button, the Fragment is called with everything inside. - Satanist Devilov
  • In general, the first link when searching on Google is metanit.com/java/android/18.2.php . just what you need, the dialog that opens when you click on the button. - Nikotin N
  • Thank you very much, tupanul something. Not looking for the right trip) - Satanist Devilov

0