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

button does not move to next page

On my side if I try to click the button it does nothing just sits at same screen, no error messages.

'''

private story mStory = new story();
private ImageView mImageView;
private TextView mTextView;
private Button mChoiceOne;
private Button mChoiceTwo;
private String mName;





public static final String TAG = storyActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_story);

    mStory.Story();
    Intent intent = getIntent();
    String mName = intent.getStringExtra(getString(R.string.key_name));

    if(mName == null)
    {
        mName = "friend";
    }

    Log.d(TAG,mName);

    mImageView = (ImageView) findViewById(R.id.storyImageView);
    mTextView = (TextView) findViewById(R.id.storyTextView);
    mChoiceOne = (Button) findViewById(R.id.choiceButtonOne);
    mChoiceTwo = (Button) findViewById(R.id.choiceTwoButton);
    mStory.Story();

}

private void loadPage(int choice)
{

   final page mCurrentPage = mStory.getPage(choice);

    Drawable drawable = getResources().getDrawable(mCurrentPage.getImageId());
    mImageView.setImageDrawable(drawable);
    mTextView.setText(mCurrentPage.getText());
    String pageText = mCurrentPage.getText();
    String.format(pageText,mName );

    mChoiceOne.setText(mCurrentPage.getChoiceOne().getText());
    mChoiceTwo.setText(mCurrentPage.getChoiceTwo().getText());

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

    });

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




}

}

'''

1 Answer

It appears you are not calling you loadPage(int choice) method at the bottom of onCreate();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_story);

    mStory.Story();
    Intent intent = getIntent();
    String mName = intent.getStringExtra(getString(R.string.key_name));

    if(mName == null)
    {
        mName = "friend";
    }

    Log.d(TAG,mName);

    mImageView = (ImageView) findViewById(R.id.storyImageView);
    mTextView = (TextView) findViewById(R.id.storyTextView);
    mChoiceOne = (Button) findViewById(R.id.choiceButtonOne);
    mChoiceTwo = (Button) findViewById(R.id.choiceTwoButton);
    mStory.Story();


    //Here is the method that I have added for you
    loadPage(0);
}