Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created December 19, 2023 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/7510c6742ec3f3700e9ddddf031a8ce3 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/7510c6742ec3f3700e9ddddf031a8ce3 to your computer and use it in GitHub Desktop.
Android Studio AlertDialog Pass Values to DialogFragment - Kotlin 2
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