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 a Simple Android App with Java Creating the Screen Layout Editing a Layout File

Jay Reyes
seal-mask
.a{fill-rule:evenodd;}techdegree
Jay Reyes
Python Web Development Techdegree Student 15,937 Points

How do I change the string without hardcoding it?

It turns out we have a Values folder in the project tree. This folder contains strings.xml Inside strings.xml, you can create a string element that contains our beloved string "Did You Know?" I decided to name it as main_page_text.

<string name="main_page_text">Did You Know?</string>

Then in activity_fun_facts.xml, I changed the value of android:text:

<TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/main_page_text" />

Voila, now I can change the string in one place instead of multiple times in multiple places.

1 Answer

Binyamin Friedman
Binyamin Friedman
14,615 Points

(Maybe post an answer and set it as best)