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.EditText;
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 MyDialog02Ex01Fragment extends DialogFragment {
    @NonNull
    private String[] aryAge;
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

        Bundle args = getArguments();
        aryAge =args.getStringArray("aryAge");
        AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
        builder.setTitle("あなたの年代");
        builder.setItems(aryAge, new MyDialogLineListener());
        Dialog dialog = builder.create();
        return dialog;
    }
    private class MyDialogLineListener implements DialogInterface.OnClickListener {
        public void onClick(DialogInterface dialog, int itemNo) {
            EditText et = requireActivity().findViewById(R.id.etDialogData);
            String itemName=aryAge[itemNo];
            et.setText(itemName);
        }
    }
}