Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created November 11, 2023 03:17
Show Gist options
  • Save codeforfun-jp/be4f474593df5ef79aa745ebfbff425b to your computer and use it in GitHub Desktop.
Save codeforfun-jp/be4f474593df5ef79aa745ebfbff425b to your computer and use it in GitHub Desktop.
How to create dialog series list basic - java
package com.example.sample;
import android.app.Dialog;
import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
public class MyDialogFragment extends DialogFragment {
String[] choices = {"りんご", "ばなな", "みかん", "ぶどう", "いちご"};
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
return new AlertDialog.Builder(requireActivity())
.setTitle("好きな果物は?")
.setItems(choices, (dialogInterface, i) ->
Toast.makeText(
requireActivity(),
String.format("「%s」を選択しました。", choices[i]),
Toast.LENGTH_SHORT)
.show())
.create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment