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 Build an Interactive Story App (Retired) Finishing the User Interface Loading Additional Pages

Dont understand something ?!

Hello.

Can somebody explain me this line of code i dont actually got this please help!?

int nextPage = mCurrentPage.getChoice1().getNextPage();

1 Answer

int nextPage = mCurrentPage.getChoice1().getNextPage();

We have the class variable mCurrentPage. This is referring to the page being displayed. This code is expected to run on any page, so they are simply passing in a variable that changes from page to page, but always knows what page is being displayed. Page in this context is the text and button choices.

Next, the two getter methods. To refresh your java I recommend reading the staff's answer on this question. Basically, it is getting what is saved in the choice 1 button for the current page, and then getting what the next page for that choice is supposed to be.

To reiterate, the program you are using saves data and displays it based on the choice selected on the previous page. This code works by getting (reading) the data saved in the choice button 1 and then getting (reading) what the next page is supposed to be. They save all of this in the int nextPage and then use that int to look up the next page's text (story) and choices (buttons).

Thanks :)

You are welcome!