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
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?
Ramiro Torrejón15,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.