0

I am designing an app. When a new user opens the app, I will sequentially show "notification card", "two-page app info card", and "contact sync card" (The picture is posted below).

Both notification and contact sync card have only 1 view but the app info card has two views. I was able to successfully implement the app info card using viewPager along with viewPagerIndicator. But if I want to implement all of three cards, should I use 3 viewPagers and one for each card?

Also, there is no need to swap back and forth between cards except two cards inside the app info card. For example, if I am currently viewing the sync contact card, I do not expect to swap back to the app info card but if I am viewing the app info card 2, I should be able to swap back to the app info card 1.

enter image description here

user3369592
  • 1,367
  • 5
  • 21
  • 43
  • I'm not sure how you're switching between the three cards, but if you only need the swipe for the middle card, that's really only the only place you need the `ViewPager`. There's no need for three of them. – Mike M. Aug 08 '19 at 22:55
  • @MikeM. thanks for your reply. So the first and third card only need to be a "view" or "fragment" ? – user3369592 Aug 09 '19 at 03:25
  • Yeah, basically. I mean, there are many ways to do this, ultimately, but `ViewPager` is specifically designed to be a touch-swipable `View` changer, so if you don't need that for the first and last cards, there's no need for it there. If you don't really need `Fragment`s, then the most lightweight setup might be a `ViewAnimator` as the root, with three children – the notification `View`, the app info `ViewPager`, and the sync `View`. You can programmatically switch between the three, and the middle `ViewPager` will be swipable automagically. Just an idea. – Mike M. Aug 09 '19 at 03:44
  • @MikeM. Thanks. Currently, I implemented the app info card using Fragment. If I also choose to implement the notification and contact cards using fragments, do I need some data structure to store three Fragments? (such as ViewAnimiator to store 3 views)? – user3369592 Aug 09 '19 at 05:09
  • No, if you're using `Fragment`s, a `ViewAnimator` will be more complicated than necessary. You can just set animations on the `FragmentTransaction`s; e.g., https://stackoverflow.com/a/4819665. – Mike M. Aug 09 '19 at 05:15
  • @MikeM. are we able to use a viewPager with viewPagerIndicator to show those 4 views but for the first and fourth views, we do not show the indicator? – user3369592 Aug 13 '19 at 20:24
  • Sorry, I don't know how I missed the notification for your last comment. Anyhoo, I had considered that, but from your description, I gathered that you don't want to be able to touch-swipe the first and last pages. If that's so, then not only would you have to modify `ViewPagerIndicator`, you'd have to subclass `ViewPager`, too, I believe, 'cause it doesn't offer any simple way to disable swiping, IIRC. Those alterations would by significantly more involved than the setup I suggested, or the `Fragment` setup you seem to be leaning toward. – Mike M. Aug 17 '19 at 08:53
  • @MikeM. So you would suggest to still use fragment, viewPager, then another fragment? and then use some kind of data structure to hold them and show them sequentially? – user3369592 Aug 17 '19 at 21:24
  • If you don't want the swipe on the first and last pages, then yeah, that's probably what I'd do. You could even stick the `ViewPager` into its own `Fragment`, too, if you want, so you're only handling `Fragment`s at the top; i.e., so you're not trying to coordinate `FragmentTransaction`s with regular `View` adds/removes. I'm not sure what you mean by data structure, though. – Mike M. Aug 17 '19 at 21:32

0 Answers0