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
Kevin Faust15,353 Points
why do we put "context" in front of getString?
when setting our title, message, and button text, we used context.getString(R.string."locationstuffhere")
I omitted the context part and the code ran fine. I also remember we usually just use getString(R.string."stuff") so im just curious what the context part is doing
Seth Kroger56,412 Points
I believe it is because it is an automatic refactoring by Android Studio. It replaces the String with Context's getString() method. Your AlertDialogFragment class isn't a descendant of Context so it needs one to call that particular getString method. However, your class is descended from Fragment that has its own getString method. When you leave context off you are using that one instead.