I have five activities/screens that I would like to be able to swipe between, each has a different function but are interrelated hence the UI concept of swiping between each.
I have found many discussions around ViewPager and PagerAdapters etc. but cannot seem to find one where swiping switches between different activity screens.
Is this even possible? Could someone point me towards an example project of this with source code? Or show me how to adapt an existing tutorial to do what I wish?
Thanks so much, have a good one!
You can’t use
ViewPagerto swipe betweenActivities. You need to convert each of you fiveActivitiesintoFragments, then combine everything in oneFragmentActivitywith theAdapteryou use withViewPager.Here’s a link that goes into detail on converting your current
ActivitiesinfoFragments.This is the Fragment topic on the Android Developers website, it has a lot of useful info.
Here’s another example (full source) that inflates
TextViewson each page.Here’s an example that I typed up:
PagerAdapter:
This should be called in
onCreateof yourFragmentActivity:This is an example of the layout you’d use for your
FragmnetActivity:To create
Fragmentcreate a new class that extendsFragment. The first two methods you’ll want tooverrideareonActivityCreatedandonCreateView.Here’s how you could do that: