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

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.DatePicker;
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 java.util.Calendar;

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

public class MyDialog06Fragment extends DialogFragment {
    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        Calendar calender = Calendar.getInstance();
        int yearNow = calender.get(Calendar.YEAR);
        int monthNow = calender.get(Calendar.MONTH);
        int dayNow = calender.get(Calendar.DAY_OF_MONTH);
        Context context =requireActivity();
        DatePickerDialog  dialog = new DatePickerDialog(context,new MyDialogListener(),yearNow,monthNow,dayNow);
        return dialog;
    }
    private class MyDialogListener implements DatePickerDialog.OnDateSetListener{
        public void onDateSet(DatePicker view, int year, int month, int day) {
            EditText et = requireActivity().findViewById(R.id.etDialogData);
            month =month +1;
            String date = year + "/" + month + "/" + day;
            et.setText(date);
            Toast.makeText(requireActivity(), "入力:"+date, Toast.LENGTH_LONG).show();
        }
    }
}
