-
-
Save codeforfun-jp/ca4eb5dbd9f0c0a47a140165414c5bd7 to your computer and use it in GitHub Desktop.
How to create dialog series list basic - kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.sample | |
| import android.app.Dialog | |
| import android.os.Bundle | |
| import android.widget.Toast | |
| import androidx.appcompat.app.AlertDialog | |
| import androidx.fragment.app.DialogFragment | |
| class MyDialogFragment : DialogFragment() { | |
| override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | |
| val choices = arrayOf("りんご", "ばなな", "みかん", "ぶどう", "いちご") | |
| val dialog = activity?.let { | |
| AlertDialog.Builder(it) | |
| .setTitle("好きな果物は?") | |
| .setItems(choices) { dialog, i -> | |
| Toast.makeText( | |
| it, "「${choices[i]}」を選択しました。", Toast.LENGTH_SHORT | |
| ).show() | |
| } | |
| .create() | |
| } | |
| return dialog ?: throw IllegalStateException("アクティビティがNullです。") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment