3

I'm currently creating an activity containing a few stages. It is supposed to start at 'stage1' and when clicking next proceed to the next stage and when clicking back go to the previous stage.

I've tried using FragmentTransaction and replace an empty container with the fragment that supposed to be every time, and added the fragments that I've passed to the back stack. It worked at the beginning, After adding a few stages it got corrupted. Suddenly when trying to move from 'stage4' to 'stage3' it passed 'stage3' and went directly to 'stage2'.

private void changeFragment(Fragment fragment, String tag) {
    FragmentTransaction ft = fm.beginTransaction().replace(R.id.frame, fragment);
    ft.addToBackStack(tag);
    ft.commit();
    fm.executePendingTransactions();
}

That's what I've tried to use to change between the fragments but it concluded in failure.

When I tried using ViewPager instead just without the tabs. Creating the movement as I wanted, when I set the currentItem if it pointed to 'stage2' it went to 'stage3'.

In conclusion, all I want to get in the end is an activity which passes through a number of fragments(forwards and backwards) without any issues.

Thanks!

androidYS
  • 55
  • 1
  • 6

0 Answers0