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

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Button;
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 MyDialog05Fragment extends DialogFragment {
    private EditText textBox;
    //private Button button;
    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        textBox = new EditText(requireActivity());
        textBox.setHint("暗証番号");
        AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
        builder.setTitle("本人確認");
        builder.setView(textBox);
        builder.setPositiveButton("入力",new MyDialogListener());
        Dialog dialog = builder.create();
        return dialog;
    }
    private class MyDialogListener implements DialogInterface.OnClickListener {
        public void onClick(DialogInterface dialog, int buttonNo) {
            String text = textBox.getText().toString();
            EditText et = requireActivity().findViewById(R.id.etDialogData);
            et.setText(text);
            Toast.makeText(requireActivity(), "ButtonNo:"+buttonNo, Toast.LENGTH_LONG).show();

        }
    }
}