Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Weather App Concurrency and Error Handling What To Do When the Network is Down

How to i add another Fragment for the no newtork connection?

Hi, question on the title, when i try to make another onCreateDialog method in my AlertDialogFrgament.java class i dont find the option, like i can only make 1 dialog.

any help?

Lauren Moineau Tonnie Fanadez Ben Jakuben

1 Answer

Ryan Dsouza
Ryan Dsouza
9,388 Points

It's SImple. You have to make a few modifications

In AlertDialogFragment

public class AlertDialogFragment extends DialogFragment {

    private String errorTitle;
    private String errorMessage;

    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

        Context context = getActivity();

//      Get activity gives us the context through which this class was called
        AlertDialog.Builder builder = new AlertDialog.Builder(context);


        return builder.create();

    public void setErrorTitle(String errorTitle) {
        this.errorTitle = errorTitle;

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;

In the MainActivity class

 AlertDialogFragment dialog = new AlertDialogFragment();
        dialog.setErrorTitle("Opps! Sorry");
        dialog.setErrorMessage("There was an error. Please try again");
        dialog.show(getSupportFragmentManager(), "error_dialog");

This way, you can add a custom title message and text for each dialog box.