0

I have one main activity and three fragments. I want to move from second fragment to third fragment.I have show logs button on 2nd fragment when click on show logs button it should take user to the third fragment which is SHOW LOGS fragment.I have done all the working code and stuff but don't know how to move from fragment to fragment. I unable to post code for some privacy concern can someone help me?

Dheeraj Joshi
  • 1,310
  • 13
  • 23
kiran
  • 77
  • 2
  • 8
  • use fragment transaction for this – Dheeraj Joshi Dec 16 '17 at 06:06
  • I wrote something like what you want [here](https://stackoverflow.com/a/46676381/3808178). Call the display.. methods (in the listener of your button) to display one of your fragment while hiding the others. – Maxime Claude Dec 16 '17 at 06:08
  • How is this even a question, if the accepted answer is the solution? I mean, how did you get to the first and second `Fragment`s to begin with? – Mike M. Dec 16 '17 at 06:57

1 Answers1

3

Use Fragment transaction to replace your second fragment with third fragment on button click, For example,

Fragment thirdFragment = new ThirdFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, thirdFragment);
transaction.addToBackStack(null);
transaction.commit();

Hope it helps!

Chithra B
  • 576
  • 2
  • 9