is it possible to create a Page View from null?

0

I'm implementing a book-style reading method and would like to put just one background image and at the time I give the Side Scroll I came across the value on the other side, just like a newly opened book. is there a way to create a ViewPager from null? , since in our basic use ViewPager already comes with something created from a view loaded with information, and in my case I would like to put only one image or something of the kind to give a book impression as I turn the pages.

Androidexplainsthe working here , but as I said it comes with values ... Home I did not put examples because the doubt is not referring to coding itself but if there are ways to encode

    
asked by anonymous 27.03.2017 / 14:46

1 answer

3

The example you refer to in the documentation is just that: an example. It uses only one fragment that is used on all pages.

What you need to do is:

  • Create a fragment for each of the pages that should be displayed by the ViewPager. The first one will have only one image, each of the others with the "values" and eventually the last one (back cover) also with only one image.

  • Implement the% method of the FragmentStatePagerAdapter so that it returns the respective fragment for each of the pages.

    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
        public ScreenSlidePagerAdapter(FragmentManager fm) {
            super(fm);
        }
    
        @Override
        public Fragment getItem(int position) {
            switch (position){
                case 0: return new FragmentPage1();
                case 1: return new FragmentPage2();
                case 2: return new FragmentPage3();
                ....
                ....
            }
            throw new IllegalArgumentException();
        }
    
        @Override
        public int getCount() {
            return NUM_PAGES;
        }
    } 
    
27.03.2017 / 15:37