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

bot .net
bot .net
10,072 Points

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 class i dont find the option, like i can only make 1 dialog.

any help?

Lauren Moineau Tonnie Fanadez Ben Jakuben

Ryan Dsouza
Ryan Dsouza
9,003 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");, "error_dialog");

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