Android Build a Simple Android App with Java Creating the Screen Layout Editing a Layout File

Jay Reyes
Jay Reyes
Python Web Development Techdegree Student 15,935 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:

        android:text="@string/main_page_text" />

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

Binyamin Friedman
Binyamin Friedman
14,615 Points

(Maybe post an answer and set it as best)