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!

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 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?

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

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

<?xml version="1.0" encoding="utf-8"?>


1 Answer

Ratul Sarna
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.