Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Blog Reader Android App Rebuilding from Scratch All About @string Resources

How is a context different than a resource?

How can I determine that I should use getResource instead of getString? Is it because we used a string array instead of just a string?

StringTest.java
String[] phoneNumberLabels = { "-home", "-work", "-mobile" };

Button saveButton = (Button) findViewById(R.id.saveButton);

saveButton.setText("SAVE");
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

</resources>

1 Answer

Ratul Sarna
PLUS
Ratul Sarna
Courses Plus Student 11,618 Points

There are two ways to learn when to use the Context method getString() and when to use getResources().getStringArray().

First is to just try using getStringArray() without calling getResources(). The IDE will prompt you to correct the error and provide suggestions through which you can choose the one that fits this scenario. Then the important part is not to just fix the error, but the next step is to look up the methods in the official documentation/API and understand them better.

Second, you can google your exact requirement. This way, someone on the forums or even the official documentation would hold the answer for you.

Thanks for all your help.