diff --git a/app/src/main/java/com/example/citrusclient/views/BookColorDialogFragment.java b/app/src/main/java/com/example/citrusclient/views/BookColorDialogFragment.java new file mode 100644 index 0000000..e04a4c8 --- /dev/null +++ b/app/src/main/java/com/example/citrusclient/views/BookColorDialogFragment.java @@ -0,0 +1,141 @@ +package com.example.citrusclient.views; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Toast; + +import com.example.citrusclient.R; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link BookColorDialogFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class BookColorDialogFragment extends Fragment { + private RadioGroup radioGroupColors; + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + public BookColorDialogFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment BookColorDialogFragment. + */ + // TODO: Rename and change types and number of parameters + public static BookColorDialogFragment newInstance(String param1, String param2) { + BookColorDialogFragment fragment = new BookColorDialogFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_book_color_dialog, container, false); + } + + int selected = 0; +// @Override + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); //親クラスである Fragment の onViewCreated() メソッドを呼び出す + view.findViewById(R.id.buttonCancel).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ((MainActivity) getActivity()).showFragment(new CreateBookFragment()); + } + }); + + radioGroupColors = view.findViewById(R.id.radioGroupColors); + radioGroupColors.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + // ラジオボタンが選択された時の処理 + RadioButton checkedRadioButton = group.findViewById(checkedId); + if (checkedRadioButton != null && checkedRadioButton.isChecked()) { + String selectedColor = checkedRadioButton.getText().toString(); + radioGroupColors.findViewById(R.id.radioButtonSprout).setOnClickListener(new View.OnClickListener() { // + @Override + public void onClick(View view) { + ((MainActivity) getActivity()).showFragment(new CreateBookFragment()); + } + }); + // 選択された色に応じた処理をここに記述する + // 例えば、選択された色をログに出力する + Log.d("ColorSelection", "Selected color: " + selectedColor); + } + } + }); + + view.findViewById(R.id.buttonOk).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ((MainActivity) getActivity()).showFragment(new CreateBookFragment()); + } + }); + + + } + + public Dialog onCreatedDialog(Bundle savedInstanceState){ + final String[] items = {"citrus","sakura","gray"}; + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + return builder.setTitle("色の種類") + .setSingleChoiceItems(items, selected, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int which) { + selected = which; + } + } + ) + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + Toast.makeText(getActivity(),String.format("[%s]が選択されました",items[selected]), + Toast.LENGTH_SHORT).show(); + } + } + ) + .create(); + } +} \ No newline at end of file