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 Ending the Story

Stephen Little
Stephen Little
8,312 Points

first page in interactive story is showing play again button

I not sure why this is doing that and really not sure what code to show. It was all looking to work right like the video, the app would crash when I got to the end page. I added in the isFinal code and now my start page shows the play again button. Here is the code for the isFinal.

 if(mCurrentPage.isFinal()){
            mChoice1.setVisibility(View.INVISIBLE);
            mChoice2.setText("PLAY AGAIN");
            mChoice2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }
        else {
            mChoice1.setText(mCurrentPage.getChoice1().getText());
            mChoice2.setText(mCurrentPage.getChoice2().getText());

            mChoice1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int nextPage = mCurrentPage.getChoice1().getNextPage();
                    loadPage(nextPage);
                }
            });

            mChoice2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int nextPage = mCurrentPage.getChoice2().getNextPage();
                    loadPage(nextPage);
                }
            });
        }

any ideas would be great, I'm taking a small break, maybe coffee will help :)

Thanks Stephen

2 Answers

Stephen Little
Stephen Little
8,312 Points

Figured it out, I have two Page constructors and I was setting mIsFinal to true in the first once but it should of been in the second one (DOH!).... so if anybody had the same problem I had I'll post the two constructors here, maybe it will help somebody someday...

 public Page(int ImageId, String text, Choice choice1,Choice choice2) {
        mImageId = ImageId;
        mText = text;
        mChoice1 = choice1;
        mChoice2 = choice2;
    }

    public Page (int imageId,String text) {
        mImageId = imageId;
        mText = text;
        mChoice1 = null;
        mChoice2 = null;
        mIsFinal = true;
    }

The above code is how it should look ;)

Cheers! Stephen

George Pirchalaishvili
George Pirchalaishvili
3,747 Points

Can you show code of your .isFinal() method?

Stephen Little
Stephen Little
8,312 Points
 private boolean mIsFinal = false;

    public boolean isFinal() {
        return mIsFinal;
    }

I did notice that in the code below there is a black line through the getDrawable();

Drawable drawable = getResources().getDrawable(mCurrentPage.getImageId());

not sure if that would be the problem or not, I think that is just letting me know that the code isn't for older version like API 14 I thbink

George Pirchalaishvili
George Pirchalaishvili
3,747 Points

Is there a method which changed value of mIsFinal?

Stephen Little
Stephen Little
8,312 Points
 private boolean mIsFinal = false;

    public boolean isFinal() {
        return mIsFinal;
    }

    public void setFinal(boolean isFinal) {
        mIsFinal = isFinal;
    }