I am developing an app in which I have an on boarding. I have a "next" button at the bottom of the layout which will load the next fragment. The problem is how to do this when I will have to go through 8 fragments. The order in which the fragments will be displayed, never changes. Should I use a counter or should I ask which fragment is being displayed and then go to the next? Any help is welcomed, thanks.
Asked
Active
Viewed 119 times
0
-
1You can use a `ViewPager` scroll to next page on click of next. – Veneet Reddy May 23 '17 at 23:06
-
You could define an interface in each Fragment, as explained here. https://stackoverflow.com/questions/24777985/how-to-implement-onfragmentinteractionlistener call some method like `onNextPage`, in which you replace the next Fragment – OneCricketeer May 23 '17 at 23:07
-
You can store all the 8 fragments in an array. When you push the next button, the fragment container will be replaced with the targeted next fragment from the array. – muazhud May 23 '17 at 23:58
-
@cricket_007 wouldn´t that mean I will have to implement 8 different interfaces in my activity? one for each fragment – Virg May 25 '17 at 17:05
-
Unfortunately, yes. – OneCricketeer May 25 '17 at 17:59
-
@cricket_007 decided to just Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.content_frame) on my container activity onclick and then just go through a series of if statements if(current.equals(getString(R.string.my_frag_title)){//go to next frag} thought that would be simpler and also better then loading them all at once – Virg May 25 '17 at 22:00
-
I never did suggest loading them all at once. A ViewPager also only would load a max of 3 at once – OneCricketeer May 25 '17 at 22:15
-
@cricket_007 finally I declared a tag for each fragment in my string res and then used a switch to verify. I did this because my frag titled will be subject to change with localization and switch needs constant values to make the match. – Virg Jun 03 '17 at 15:05