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 trialMUZ141046 Munyaradzi Nhema
1,773 PointsHELP
V
import android.content.Context;
import android.os.Bundle;
public class AlertDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getActivity();
// Insert code here!
AlertDialog.Builder builder = new AlertDialog.Builder(context);
return null;
}
}
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.io.IOException;
public class MovieActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie);
// Get some movie information!
String apiUrl = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=xyz&q=hobbit";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(apiUrl)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
}
@Override
public void onResponse(Response response) throws IOException { }
});
}
}
1 Answer
Harry James
14,780 PointsHey Munyaradzi!
You've got the first bit! Next, we want to append to the builder 3 methods to set the title, the message and the button text (Where we also set the null listener, as the second parameter).
Here's some links to help you out.
First, see if you can find the methods you need to set these 3 methods for the builder. They're over here on the AlertDialog.Builder documentation.
Next, we want to create the dialog. There's a method we can run off the builder to create it. Perhaps you can find it on the Dialog documentation? (Hint: It's in the first code block).
Got it? Here's the last step now. As our AlertDialogFragment is actually a DialogFragment (It extends the class). If you're not sure what method to use, as you've probably guessed by now, it's in the documentation (Take a look at the 4th code block)!
Hopefully this information should arm you to tackle the challenge! I understand I have just linked you to 3 documentation links but this is so that you know how to solve problems like this in the future by yourself. Also, I don't want to straight up give you the answers here - other people can use them for the challenge and also, you don't learn that way!
If there's anything you're still stuck on then please, feel free to give me a shout and I'll be happy to help out :)