Conditional wizard/initialization with ViewPager
Asked Answered
G

0

8

At first start the app will have to do some initial configuration, and so I need to load pages and slide it based on the user decision on a page. So I would like to set and to slide to left the correct page after that decision with animation. The visual step indicator can even change... Everything should be dynamic as following:

enter image description here

But ViewPager always loads at least the next page itself after few moments (setOffscreenPageLimit(0) isn't allowed); Actually when user chooses an option from the setup fragment, the slide animation runs through all middle pages and they are visible during animation because I use mIndicator.setCurrentItem(5, true);

I was able to disable the gesture slide but the arc animation doesn't work. I could set mIndicator.setCurrentItem(5, false); but I still want the slide animation after user clicks the buttons to reach the appropriate page.

The Fragment setup has an Interface listener that the Activity implements. The listeners are called from the buttons and the implemenation looks like:

...
@Override
public void onRestoreLocal() {
    //The indicator contains ViewPager and it switches the page as well.
    mIndicator.setCurrentItem(5, true);
}
...

public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
    ...
    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        // Return a PlaceholderFragment.
        Log.d(TAG, "getItem position="+position);

        switch (position) {
        case 0:
            return PlaceholderFragment.newInstance(R.layout.setup_fragment_1, position);
        case 1:
            return PlaceholderFragment.newInstance(R.layout.setup_fragment_2, position);
        case 2:
            return SetupChoiceFragment.newInstance();
        case 3:
            return SetupCreateFragment.newInstance();
        case 4:
            return SetupImportFragment.newInstance();
        case 5:
            return SetupRestoreFragment.newInstance();
        }
        return null;
    }
    ...
}
  1. Should I set the number of pages to 6 in order to jump to the page chosen? But how to maintain Slide Animation and PageIndicator always =4!
  2. How to avoid the automatic loading of the next slide or it doesn't matter?
  3. Should I stick to use the ViewPager or manage the Fragment navigation myself setting the custom sliding animation (with next/back) on the FragmentTransaction without using FragmentStatePagerAdapter and managing the backstack while going back? or what others component exists for a wizard configuration?

Also, how to go back always on page#3 with gesture animation slide blocking right manual gesture?

Giulietta answered 6/5, 2015 at 9:32 Comment(2)
I've found the solution. I rewrote completely the architecture of handling the pages based on the solution of Roman Nurik with his example in GitHub github.com/romannurik/Android-WizardPager - I will add my solution in the answer soon. But it is a complicated one...Giulietta
From Angular 13 this custom component is superfluous. They have finally "invented" the component that support vertical and horizontal they way it should since origin.Giulietta

© 2022 - 2024 — McMap. All rights reserved.