-
-
Save codeforfun-jp/7510c6742ec3f3700e9ddddf031a8ce3 to your computer and use it in GitHub Desktop.
Android Studio AlertDialog Pass Values to DialogFragment - Kotlin 2
This file contains 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
class MyDialogFragment : DialogFragment() { | |
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | |
val dialog = activity?.let { | |
// 値を受け取る | |
val title = arguments?.getString("TITLE", "") | |
val number = arguments?.getInt("NUMBER", 0) | |
AlertDialog.Builder(it) | |
.setTitle(title) | |
.setMessage("受け取った値は$number") | |
.setPositiveButton("OK") { _, _ -> } | |
.create() | |
} | |
return dialog ?: throw IllegalStateException("アクティビティがNullです。") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment