Question

I want users to be able to swipe to the same activity but only change the index of the screen that is to be displayed, everything stays the same but the index is changed and invalidate() is called. I realize i could swipe to another instance of the same activity and pass the index to it, but is there anyway to reuse it (i.e. fake the swipe) without having to destroy and create a new one.

Each separator represents a page that i want to swipe between. The number of pages I'm using is dynamic

1       2       3   

| 1 2 3 | 13 15 | 35 39 |
| 4 5 6 | 17 19 | 37 40 |
| 7 8 9 | 21 23 | 41 43 |

Was it helpful?

Solution

Could you? Probably. Depends on your data structure and how you're populating the content. However, I don't believe it's the right approach, based on what you've shown. Rather, it looks like what you are really looking for is a single Activity that hosts a ViewPager, with a FragmentPagerAdapter. You would have a single "PageFragment", which you could instantiate with the index as an argument, and then populate the contents of the Fragment based on that index.

See: ViewPager
See: FragmentPagerAdapter

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top