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 trialTetsuya Uno
21,024 PointsButton text doesn't show up in emulator
Even though button text shows up in preview pane, it doesn't when I run the app on the emulator. The button itself seems to be there even on the emulator judging from the background.
Here're my string.xml and activity_story.xml
string.xml
<resources> <string name="app_name">Signals from Mars</string> <string name="key_name">name</string> <string name="signals_from_mars_title_image">Signals from Mars title image</string> <string name="start_your_adventure">Start Your Adventure</string> <string name="enter_your_name">Enter Your Name</string> <string name="page0">On your return trip from studying Saturn\'s rings, you hear a distress signal that seems to be coming from the surface of Mars. It\'s strange because there hasn\'t been a colony there in years. Even stranger, it\'s calling you by name: \"Help me, %1$s, you\'re my only hope.\"</string> <string name="page0_choice1">Stop and investigate</string> <string name="page0_choice2">Continue home to Earth</string>
<string name="page1">You deftly land your ship near where the distress signal originated. You didn\'t notice anything strange on your fly-by, but there is a cave in front of you. Behind you is an abandoned rover from the early 21st century.</string>
<string name="page1_choice1">Explore the cave</string>
<string name="page1_choice2">Explore the rover</string>
<string name="page2">You continue your course to Earth. Two days later, you receive a transmission from HQ saying that they have detected some sort of anomaly on the surface of Mars near an abandoned rover. They ask you to investigate, but ultimately the decision is yours because your mission has already run much longer than planned and supplies are low.</string>
<string name="page2_choice1">Head back to Mars to investigate</string>
<string name="page2_choice2">Continue home to Earth</string>
<string name="page3">Your EVA suit is equipped with a headlamp, which you use to navigate the cave. After searching for a while your oxygen levels are starting to get pretty low. You know you should go refill your tank, but there\'s a very faint light up ahead.</string>
<string name="page3_choice1">Refill at ship and explore the rover</string>
<string name="page3_choice2">Continue towards the faint light</string>
<string name="page4">The rover is covered in dust and most of the solar panels are broken. But you are quite surprised to see the on-board system booted up and running. In fact, there is a message on the screen: \"%1$s, come to 28.543436, -81.369031.\" Those coordinates aren\'t far, but you don\'t know if your oxygen will last for a trip there and back.</string>
<string name="page4_choice1">Explore the coordinates</string>
<string name="page4_choice2">Return to Earth</string>
<string name="page5">After a long walk slightly uphill, you end up at the top of a small crater. You look around, and are overjoyed to see your favorite android, %1$s-S1124. It had been lost on a previous mission to Mars! You take it back to your ship and fly back to Earth.</string>
<string name="page6">You arrive home on Earth. While your mission was a success, you forever wonder what was sending that signal. Perhaps a future mission will be able to investigateā¦</string>
<string name="story_image_content_description">Story page image</string>
</resources>
--
activity_story.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.uk_100.interactivestory.ui.StoryActivity">
<Button
android:id="@+id/choice1Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:textColor="#3A8AEC"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/choice2Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="@string/page0_choice1" />
<Button
android:id="@+id/choice2Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:textColor="#3A8AEC"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="@string/page0_choice2" />
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/white"
app:layout_constraintBottom_toTopOf="@+id/choice1Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/storyImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/story_image_content_description"
android:scaleType="fitXY"
tools:src="@drawable/page0" />
<TextView
android:id="@+id/storyTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:lineSpacingExtra="8sp"
android:textSize="16sp"
tools:text="@string/page0" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
2 Answers
Nick Bratt
2,113 PointsFor predefined text you should be the android prefix as opposed to the tools prefix. So it would something like android:text="something here"
Tetsuya Uno
21,024 PointsThank you, it worked!