Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to open a fragment from another fragment using binding?

How to open a Fragment from another Fragment?

I basically have a button inside of my HomeFragment.kt and I want to make it to redirect me to AboutFragment but I’m not sure how to make it. I tried different methods from Stack but nothing worked… Any suggestions? I wanna open the new fragment as I will open from navigation drawer.

Here is the button but my code just work with activities… Not with fragments…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

binding.aboutUsBtn.setOnClickListener {
    val intent = Intent(activity, AboutFragment::class.java)
    startActivity(intent)
}

>Solution :

Try this code plz:

FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.home_layout, new ChatFragment(), "second fragment"); //My second Fragment
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading