Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Android

I'm learning android and want to know how do I create a back and next button so that people can click on it and view the previous or next textviews or images. I'm really confused because I can't seem to figure this out. Any help please?

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

How do you want your buttons to look? Do you have a simple mockup you can link to in here? Doesn't matter if it's crude - it will help us figure out what you are trying to achieve. To link an image, upload it to a site like imgur.com and either just paste in the URL or use the Markdown syntax (see Markdown Cheatsheet below) to include the image directly.

Hi Ben

Have a look at this app: https://play.google.com/store/apps/details?id=com.cmoshe.relationship.tips It has a left and right (prev and next) arrow that allows you to click on it and move through the quotes. How can I achieve that? I am so amazed at your Crystal Ball app course. It is a great course that teaches you by showing and it is so easy to follow unlike most. It would be great if you could create more courses where you show how to build a complete app from start to finish. I hope I make sense in my above request? I want to create a quote app where I display 100 or more quotes and let the user click on a next or previous button to navigate. Thank you Ben

Ben Jakuben
Ben Jakuben
Treehouse Teacher

I apologize for my late reply. That should be fairly simple to set up. In the Crystal Ball app we had one button you could press to display an answer. To make it more like the app you linked to, you'd need to add another button to the display using the Graphical Layout Editor. Then you would add a new OnClickListener for that button just like how we do it with the original button. One OnClickListener would switch to the previous quote and the other would switch to the next quote.

To display the quotes, you'd have to update the TextView again like we do with the Crystal Ball app. Let's say you have an array of 100 different quotes. The button could change the index of the array to get different quotes and then reset the TextView text with the new quote from the array.

Best of luck!