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 trialRicky Sparks
22,249 PointsNeed Help with JAVA code?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
2 Answers
poltexious
Courses Plus Student 6,993 PointsHey there,
I also got stuck on task 3/4, and did not get it right the first time.
This is the working code for this task:
/*** This code is an excerpt from a class that extends Activity ***/
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.dialog_title));
builder.setMessage(getString(R.string.dialog_message));
Although the .xml file with strings is called strings.xml, you still have to refer to 'R.string.YOUR_OWN_DEFINED_STRING_KEY' and not just 'strings.YOUR_OWN_DEFINED_STRING_KEY'. In my case, I used 'dialog_title' and 'dialog_message' as the YOUR_OWN_DEFINED_STRING_KEY, respectively.
Christopher Eckhardt
9,953 PointsAlertDialog.Builder builder = new AlertDialog.Builder(YourActivityGoesHere.this);
builder.setTitle(R.string.blah_blah)
.setMessage(R.string.your_message);
AlertDialog dialog = builder.create();
I didn't fully understand your question, but I hope this helps.
Ricky Sparks
22,249 PointsRicky Sparks
22,249 Pointsstuck on 3/4 challenge
Now switch back to CodeChallenge.java and set the title and message for your Builder variable using the string resources you just added.