How to make the transition from one fragment to another using the button on the screen? (Without TabLayout). If I can, I will be grateful for the code.

    1 answer 1

    You can create an interface

    public interface IClickListener{ void onClick(); } 

    Further in the fragment

     private IClickListener mClickListener; //Some code @Override public void onAttach(@NonNull Context context) { super.onAttach(context); mClickListener = (IClickListener) context; } Button button = view.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mClickListener.onClick(); }); 

    Further in your activit with a fragment

     public class Activity implements ILoginListener { //Some code @Override public void onClick() { startFragment(yourFragment); } private void startFragment(Fragment fragment) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container, fragment); transaction.addToBackStack(null); transaction.commit(); } } 

    Here you can read additional information https://startandroid.ru/ru/uroki/vse-uroki-spiskom/176-urok-106-android-3-fragments-vzaimodejstvie-s-activity.html