Android Build an Interactive Story App Finishing the User Interface Loading the First Page

storyTextView not importing correctly

The storyTextView under the findViewByID(R.id.storyTextView) is underlined red and I cannot make it go away

package com.example.interactivestory.ui;

import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView;

import com.example.interactivestory.R; import com.example.interactivestory.model.Page; import com.example.interactivestory.model.Story;

public class StoryActivity extends AppCompatActivity {

public static final String TAG = StoryActivity.class.getSimpleName();

private String name;
private Story story;
private ImageView storyImageView;
private TextView storyTextView;
private Button choice1Button;
private Button choice2Button;



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

    storyImageView = (ImageView)findViewById(R.id.storyImageView);
    storyTextView = (TextView)findViewById(R.id.storyTextView);
    choice1Button = (Button)findViewById(R.id.choice1Button);
    choice2Button = (Button)findViewById(R.id.choice2Button);

    Intent intent = getIntent();
    name = intent.getStringExtra(getString(R.string.key_name));
    if (name == null || name.isEmpty()) {
        name = "Friend";
    }
    Log.d(TAG, name);

    story = new Story();
    loadPage(0);

}

private void loadPage(int pageNumber) {
    Page page = story.getPage(pageNumber);

    Drawable image = ContextCompat.getDrawable(this, page.getImageId());
    storyImageView.setImageDrawable(image);

    String pageText = getString(page.getTextId());
    // add name is placeholder include. Wont add if not

    pageText = String.format(pageText, name);
    storyTextView.setText(pageText);

    choice1Button.setTextColor(page.getChoice1().getTextId());
    choice2Button.setTextColor(page.getChoice2().getTextId());
}

}

2 Answers

Martin Klestil
Martin Klestil
5,515 Points

which ID did you give the TextView?

activity_story.xml

<TextView
                android:id="@+id/storyTextView"
/>

That did it, I forgot to write story in front of it!

Thanks for your help