neo108
neo108

Reputation: 5244

Display multiple sayings as separate Activity in android

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...

enter image description here

For this...

  1. Do I have to create a separate Activity with its Layout for each page (famous quote screen)? (If there are 20 quotes then do I have to create 20 Activities?)
  2. If yes to question 1, then do I need dedicated "Back" and "Next" buttons for each page? (Is there any way of using the same back & next buttons globally)?

Any advice is greatly appreciated.

Upvotes: 0

Views: 181

Answers (3)

djjolicoeur
djjolicoeur

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

codeMagic
codeMagic

Reputation: 44571

Use ViewPager and Fragments. This way you don't have to create separate Activitys and Layouts. 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 Layouts consistent with less code which is probably what you would want for something like this

Upvotes: 1

Gabe Sechan
Gabe Sechan

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

Related Questions