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

What is the Strings.xml file for?

Hi, I started the Android development track and noticed the yellow bar. The instructor said to see if I could figure out how to make the warning disappear and solve the issue, so I did. Now what I want to know is, what are those strings used for in strings.xml. My first guess would be like with CSS how you have IDs and classes but since we already have IDs for each component that doesn't really apply. Thanks

<resources>

<string name="app_name">Fun Facts</string>
<string name="did_you_know">Did you know?</string>
<string name="action_settings">Settings</string>
<string name="ants_stretch">Ants stretch when they wake up in the morning.</string>
<string name="next_fun_fact">Next Fun Fact</string>

</resources>

EDIT: Seems as if the string name is like an ID or class too but why would I need an ID and name?

1 Answer

Strings.xml is a way to create static string constants in one place. that way if you have a string you reference multiple places, if you ever want to change it you can just change it in one place instead of going through all your code and changing it multiple times. there are other advantages as well (multi language support etc), but you dont HAVE to use it, it just makes things easier

Thanks. Not sure how I didn't get that in the first place.