Jak korzystać z fragmentu okna dialogowego? (showDialog przestarzałe) Android

Rozumiem, że istnieje ta dokumentacja

http://developer.android.com/reference/android/app/DialogFragment.html#AlertDialog

ale jako nowy uczeń systemu Android / Java nie jest łatwo zrozumieć ilość kodu wymaganego od napisania prostego okna dialogowego alertu, które pojawia się z komunikatem 2 opcji (tak / nie).

Oto kod, który aktualnie mam w moim pliku MainActivity:

final private int RESET_DIALOG = 0;

    private OnClickListener resetButtonListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialog(RESET_DIALOG);

        }
    };

    protected android.app.Dialog onCreateDialog(int id) {
        switch(id) {
        case RESET_DIALOG: 
            AlertDialog.Builder builder = new Builder(this);
            return builder
                    .setMessage("Are you sure you want to reset the count?")
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {    

                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            Toast.makeText(MainActivity.this, "Did not reset!", 5).show();

                        }
                    })

                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {


                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            Toast.makeText(MainActivity.this, "Did Reset!", 5).show();

                        }
                    })
                    .create();
        }
        return null;
    };

To jest moja próba wykonania instrukcji na stronie Android: Główny plik aktywności:

final private int RESET_DIALOG = 0;

    private OnClickListener resetButtonListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, MainDialog.class);
            startActivity(intent);

        }
    };

    protected android.app.Dialog onCreateDialog(int id) {
        switch(id) {
        case RESET_DIALOG: 
            AlertDialog.Builder builder = new Builder(this);
            return builder
                    .setMessage("Are you sure you want to reset the count?")
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {    

                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            Toast.makeText(MainActivity.this, "Did not reset!", 5).show();

                        }
                    })

                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {


                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            Toast.makeText(MainActivity.this, "Did Reset!", 5).show();

                        }
                    })
                    .create();
        }
        return null;
    };

Następnie utworzyliśmy klasę MainDialog: (Naprawdę zgubiłem się, jak to zrobić poprawnie lub zastosować)

package com.proteintracker;

import android.support.v4.app.DialogFragment;

public class MainDialog extends DialogFragment {
    public static MyAlertDialogFragment newInstance(int title) {
        MyAlertDialogFragment frag = new MyAlertDialogFragment();
        Bundle args = new Bundle();
        args.putInt("title", title);
        frag.setArguments(args);
        return frag;
    }
}

Nie jestem pewien, czy miałem utworzyć nową klasę dla tego fragmentu i jak zastosować go do mojego bieżącego okna dialogowego na ekranie aktywności.

questionAnswers(4)

yourAnswerToTheQuestion