Kailash Karankal
Kailash Karankal

Reputation: 3

How to replace the new fragment to old fragment inside frame layout without viewpager in android?

  1. I'm trying below code to replace the new fragment, but it's not Replaced.

    android.app.Fragment Manager fragmentManager = ((Activity) context). getFragmentManager(); android.app.FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.frame_container, menuItemDetailsFragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit();

Upvotes: 0

Views: 642

Answers (1)

Umar Ata
Umar Ata

Reputation: 4258

You actually need to use the replace function Just replace this line of code

fragmentTransaction.add(R.id.frame_container, menuItemDetailsFragment); 

with this

fragmentTransaction.replace(R.id.frame_container, menuItemDetailsFragment); 

Upvotes: 1

Related Questions