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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![shiva csk](https://secure.gravatar.com/avatar/88ae531422425e8931c3776040facd4c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
shiva csk
646 Pointshow to add a string in strings.xml
usage of strings.xml?
2 Answers
![Valerie Makumire](https://secure.gravatar.com/avatar/d9724f873f5c49f5d0a967b2aa25420f?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Valerie Makumire
3,262 PointsGo into strings.xml which is located in the values folder. Then use the following format to add a string to it.
<string name="NameOfTheString">Some string that you want</string>
Then you can use the string in other XML files by referencing it like this:
@string/NameOfTheString
To use the string in your Java files you must use the getString() method like this:
getString(R.string.NameOfTheString);
Be aware though you cannot use this in classes outside activities unless you manage to get a context variable.
![shiva csk](https://secure.gravatar.com/avatar/88ae531422425e8931c3776040facd4c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
shiva csk
646 Pointsthank u so much, and how to set the text of a button using a string??can u help me