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();
Asked
Active
Viewed 627 times
0

Kailash Karankal
- 3
- 4
-
Do you mean navigating From one fragment to another ? – Ahlem Jarrar Dec 11 '16 at 17:48
-
http://stackoverflow.com/questions/5658675/replacing-a-fragment-with-another-fragment-inside-activity-group check this and see if it answers your problem – Ahmed Saad Harmoush Dec 11 '16 at 17:50
-
Yes sir, when user click on the old fragment button, then opens a new fragment.Finally means replace the new fragment. I did above code but the fragments are overlapping. – Kailash Karankal Dec 11 '16 at 17:51
1 Answers
1
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);

Umar Ata
- 4,170
- 3
- 23
- 35