-
-
Save codeforfun-jp/9843e763c58d3adb7bec04613f24094f to your computer and use it in GitHub Desktop.
Android Studio AlertDialog Pass Values to DialogFragment - Kotlin 1
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 MainActivity : AppCompatActivity(){ | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
findViewById<Button>(R.id.btn).setOnClickListener { | |
val dialogFragment = MyDialogFragment() | |
// 値を渡す | |
val bundle = Bundle().apply { | |
putString("TITLE", "こんにちは") | |
putInt("NUMBER", 123) | |
} | |
dialogFragment.arguments = bundle | |
dialogFragment.show(supportFragmentManager, "my_dialog") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment