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 trialMichael McDonald
2,877 PointsHow 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?
String[] phoneNumberLabels = { "-home", "-work", "-mobile" };
Button saveButton = (Button) findViewById(R.id.saveButton);
saveButton.setText("SAVE");
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
1 Answer
Ratul Sarna
Courses Plus Student 11,618 PointsThere 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.
Michael McDonald
2,877 PointsMichael McDonald
2,877 PointsThanks for all your help.