Is it possible to create a Page View from null?

Asked

Viewed 37 times

0

I am implementing a book style reading method and would like to put just a background image and at the time I give the Scroll side came the value on the other side, exactly like a newly opened book.
The question is, is there a way to create a Viewpager from null?,Since in our basic use Viewpager already comes with something created Starting from a view loaded with information,.

inserir a descrição da imagem aqui

The android explains the working here, but as I said comes with values...
I did not put examples because the doubt is not related to coding itself but if there are ways to encode

  • I couldn’t understand what you mean by "create a Viewpager from null".

  • starting from something worthless only a Fragment with an image behind @ramaral, imagine book, with a cover and inside the pages, would be like this, a cover only being there, in case my image, and after the values if I tried to pull giving the scroll would come the values... I put an image I think it explains better what I want

1 answer

3


The example referred to in documentation that’s right: an example.
In it is used only one Fragment that is used on all pages.

What you need to do is:

  • create a Fragment for each of the pages that must be presented by Viewpager.
    The first will have only one image, each of the others with the "values" and eventually the last (back cover) also with only one image.

  • implement the method getItem() of Fragmentstatepageradapter so that for each of the pages the respective Ragment.

    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;
        }
    } 
    
  • I get it, I just need to keep it loaded like it’s the background I wouldn’t necessarily need to create null, I can leave it behind and just make the comparison if that’s at the 0 position go here or if it’s at the end the opposite, not necessarily leaving Fragment empty is a great solution and well adaptable

Browser other questions tagged

You are not signed in. Login or sign up in order to post.