package jp.gihyo.mitoma.android.s1201dialog.fragment;

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

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

import jp.gihyo.mitoma.android.s1201dialog.R;

public class MyDialog01Fragment 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());
        builder.setNeutralButton("CANCEL",new MyDialogYesNoListener());
        Dialog dialog = builder.create();

        return dialog;
    }
    private class MyDialogYesNoListener implements DialogInterface.OnClickListener{
        public void onClick(DialogInterface dialog,int buttonNo){
            EditText et = requireActivity().findViewById(R.id.etDialogData);
            String buttonName="";
            switch(buttonNo){
                case DialogInterface.BUTTON_POSITIVE:
                    buttonName = "YESボタン";
                    break;
                case DialogInterface.BUTTON_NEGATIVE:
                    buttonName = "NOボタン";
                    break;
                case DialogInterface.BUTTON_NEUTRAL:
                    buttonName = "CANCELボタン";
                    break;
                default:
                    break;
            }
            et.setText(buttonName);
        }
    }
}
