Reputation: 5244
I am very new to Android development and so I am seeking advice for the best means to implement the following...
I would like to display a few famous sayings in an app - one page at a time, with back and next button navigating to the previous and next sayings. Just like below...
For this...
Activity
with its Layout
for each page (famous quote screen)? (If there are 20 quotes then do I have to create 20 Activities?)Any advice is greatly appreciated.
Upvotes: 0
Views: 181
Reputation: 484
I would use a tabbed layout and hide the tabs. This should help with how to hide the tabs. How to hide a tab in Android tab layout?
Upvotes: 1
Reputation: 44571
Use ViewPager
and Fragment
s. This way you don't have to create separate Activity
s and Layout
s. You just had separate pages for each new screen. You also won't have to create new buttons for each page.
Check out the Docs about getting started with it
This tutorial is a good one to see how to use ViewPager
. It steps you through using it and has source code that you can download and tailor to what you need it for. This is a good way to keep the Layout
s consistent with less code which is probably what you would want for something like this
Upvotes: 1
Reputation: 93678
No, you don't need separate activities. Just one will do it. Make your activity have a pageNumber variable, default it to 0 on creation. When they hit back or next, increment it. Then call setText on the TextView holding the quote and change it to the new quote's string.
Upvotes: 2