package jp.gihyo.mitoma.android.p022widgetstest;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

public class RegistFragment extends DialogFragment {
    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
        builder.setTitle("登録の確認");
        builder.setMessage("登録を実行了しますか?");
        builder.setPositiveButton("YES",new MyDialogYesNoListener());
        builder.setNegativeButton("NO",new MyDialogYesNoListener());
        Dialog dialog = builder.create();

        return dialog;
    }
    private class MyDialogYesNoListener implements DialogInterface.OnClickListener{
        public void onClick(DialogInterface dialog,int buttonNo){
            String buttonName="";
            switch(buttonNo){
                case DialogInterface.BUTTON_POSITIVE:
                    buttonName = "YESボタン";
                    break;
                case DialogInterface.BUTTON_NEGATIVE:
                    buttonName = "NOボタン";
                    break;
                default:
                    break;
            }
            Toast.makeText(requireActivity(),buttonName + "ON",Toast.LENGTH_LONG).show();
        }
    }
}
