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 Build a Weather App (2015) Concurrency and Error Handling Configuring the Alert Dialog

Does it make any difference whether to use context.GetString() or not when setting title value of AlertDialog.Builder?

When using opt-Enter to extract string resource as instructed in the video, my Android Studio didn't convert the string to context.GetString(R.string.error_title) but to simply R.string.error_title.

The code runs fine to display the error massage with AlertDialog and nothing weird showed in Log after execution.

So, does it make any difference whether to use context.GetString() or not when setting title value of AlertDialog.Builder?

Thanks!

I'm seeing the same thing. Are you using Android Studio 1.3.2?

1 Answer

Ramiro Torrej贸n
Ramiro Torrej贸n
15,286 Points

You can check the method AlertDialog.Builder(context).setTitle() documentation here: http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setTitle(java.lang.CharSequence)

Context.getString(int resId): Receives as parameter the given resource id (integer) , and R.string.error_title: Is the resource id (integer)

But the setTitle method as you can see in the documentation can receive a CharSequence or an integer (resourceId). That's why it works with context.GetString(R.string.error_title) or R.string.error_title.

Gavin Ralston
Gavin Ralston
28,770 Points

I guess where I'm failing to understand why Android Studio did this in previous versions is because.... isn't the context of R (resources) already "the entire app"?

When would a situation come up where I'd want to use a Context to get a string from R that would produce different results than just accessing the property/field directly from R?